2

i'm trying to save file to my drive using NodeJS as backend. So far, i managed to access

https://${sites}/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents')/Files('test.xlsx')/$value

and get the return like;

enter image description here

so far, no error message appears and i assume the request to the above url is succeed. what can i do with this data? i tried to use fs.write() but then when i open the file, it corrupts. any response from you guys is highly appreciated.

thanks.

Note: i tried using this method Download sharepoint document with REST as binary file not working for me but still didn't work.

2 Answers 2

2

There are some libraries available for such a task. For example consider sppull.
With sppull you can easily download file with just a few lines of code:

var sppull = require("sppull").sppull;

var context = {
  siteUrl: "http://contoso.sharepoint.com/subsite",
  creds: {
    username: "[email protected]",
    password: "_Password_"
  }
};

var options = {
  spRootFolder: "Shared%20Documents/Contracts",
  dlRootFolder: "./Downloads/Contracts"
};
sppull(context, options)....

Also check out sp-download

1
  • When using sppull, please do consider the %20 in the url. I spend a day (!) on this problem when it got to me, that I should just have used a simple space bar " " instead. So in my case, it would be "Shared Documents/Contracts". Even if I copy the url from SharePoint and get the %20 inside the url, I need to replace them with a spacebar. Commented Aug 9, 2022 at 10:44
0

i've found out the solution for my case based on this thread :

https://stackoverflow.com/questions/5294470/writing-image-to-local-server

everything works just fine.

thanks.

Your Answer

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

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