1

According to the following link:

Working with folders and files with REST

I can add a file using

url: http://site url/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/add(url='a.txt',overwrite=true)
method: POST
body: "Contents of file"
Headers: 
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    content-length:length of post body

I am testing this with Postman. In my post request I set the body to form-data and add a file parameter with a text file called "a.txt". The text file contains the text:

one
two
three

When I execute my request in Postman my text file is present in SharePoint. When I open the file on SharePoint the contents of the file is:

----------------------------235004993628819232914336
Content-Disposition: form-data; name="file"; filename="a.txt"
Content-Type: text/plain

one
two
three
----------------------------235004

I want to do this action by only using plain HTTP calls. Is this behaviour correct? It looks like a file is created and the content is filled with my formdata.

0

Setting the body to binary in Postman fixed my problem. Key is setting the correct content-length otherwise the file will get corrupted.

Get the content length of thee file with PowerShell

$file = "c:\temp\file.docx"
(Get-Item $file).Length

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.