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.
9,913 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.
2,734 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,401 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.