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?

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

1 Answer 1

1

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.

1
  • 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...
    – user74877
    Commented Apr 2, 2018 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.