Upload File to SharePoint through REST API

Ramakrishnan Venkatesan 106 Reputation points
2021-09-13T06:30:01.547+00:00

Hello,

I am uploading ".xlsx " file into SharePoint online using REST API /_api/Web/GetFolderByServerRelativeUrl('-------')/files/add,

My upload is successful, but noticed after uploading file, it contains some additional comments as per below in the top of file, due to that, I am unable to process file .

Please advise.

Content-Type: application/octet-stream;
name=<....,XLSD>
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="filename"; filename="filename"

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,740 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,006 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ramakrishnan Venkatesan 106 Reputation points
    2021-09-23T01:45:27.303+00:00

    Yes, This has been resolved. Thank you.


1 additional answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 35,866 Reputation points Microsoft Vendor
    2021-09-14T02:28:02.81+00:00

    Hi @Ramakrishnan Venkatesan ,
    Per my test,I uploaded a file successful and correctly with following api:

    _api/Web/GetFolderByServerRelativeUrl('/sites/abc/FolderTest/Test')/Files/add(url='rename.xlsx',overwrite=true)')  
    

    We can set the file name after '/Files/add'. Since the error might caused setting filename by headers.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.