1

How can I upload a file to the current web SiteAssets or document library using the spfx httpClient? Is there a code sample I can learn from?

1

I much prefer using the new PnP-JS-Core to do file uploading. It's a nice library from PnP and provides a fluent API for the REST endpoints - as a bonus it works with traditional, sprequestexecutor or node-fetch and supports REST batching.

https://github.com/OfficeDev/PnP-JS-Core/ https://github.com/pnp/pnpjs

https://blogs.msdn.microsoft.com/patrickrodgers/

The Files.Add method would be here:

http://officedev.github.io/PnP-JS-Core/classes/_sharepoint_rest_files_.files.html#add

https://pnp.github.io/pnpjs/sp/docs/files/#adding-files

  • That's awesome, @JohnLiu. I have to give it a shot. – Rafael Rocha Sep 9 '16 at 18:45
  • All three links are non functioning.... Can you update? – zainul Mar 13 at 6:18
0

I'm not aware of any code samples specifically for the new framework but you can refer to the SharePoint REST API File Documentation for the available operations or this example that demonstrates how to upload a file using the REST API. Note that both the documentation and example assume you're using the cross-domain library which is not needed in the new framework so the URLs to the services are going to be a bit different. For example in the new framework you don't need the SP.AppContextSite(@target) portions of the url.

Hope that helps

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.