1

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

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: "user@contoso.com",
    password: "_Password_"
  }
};

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

Also check out sp-download

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, privacy policy and cookie policy

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