1

I'm working on a Word add-in with a form for selecting SharePoint Online documents, using the REST API.
At the moment, I was able to download the file directly by the URL following this MSDN article:

https://....com/sites/site/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/site/folder/Test.docx')/$value

However, this downloads the file with the name $value instead of the correct filename. Is it possible to get the actual name through REST?

  • Get any property using:_api/Web/GetFileByServerRelativePath(decodedurl='/sites/site/folder/Test.docx')/Title.. – Deepmala Mar 23 '18 at 3:24
2

Because when you download the file by the REST API, you just get the stream of the file even though you have downloaded the file.

https://....com/sites/site/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/site/folder/Test.docx')/$value

I suggest you could get the stream of the file by the REST API and save the file to the local with the correct file through the JavaScript code.

There is a similar post:

https://stackoverflow.com/questions/23451726/saving-binary-data-as-file-using-javascript-from-a-browser

More reference:

Sending and Receiving Binary Data.

  • Although unwanted, this is what I had to end up doing. I wanted to avoid saving locally so that Word could use the auto-save to cloud feature, but oh well... – SO used to be good Apr 2 '18 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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