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?


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


The Files.Add method would be here:



| improve this answer | |
  • 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 '19 at 6:18

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

| improve this answer | |

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.