I have noticed a bug when using the PnP library for SPFX to upload multiple attachments.

Using: sp-pnp-js@3.0.10 targeting: SharePoint Online

Expected Behavior Question

When uploaded multiple attachments of any size the promise setup up in item.attachmentFiles.addMultiple(attachments) will chain the requests and upload them correctly

Observed Behaviour

When using the item.attachmentFiles.addMultiple(attachments), it is intermittently causing a 409 error due to conflicts in the upload, my research has led me to believe this is caused by one file not being fully uploaded before moving onto the next, in the test case that most commonly causes this the files are approximately 3Mb in size. The error is more likely to occur the more files that are being uploaded. All files uploaded have different names and content.

Upload attachments error

Steps to Reproduce

Files are stored in an array in the state and pulled out and converted into an array of attachments before being uploaded with item.attachmentFiles.addMultiple(attachments) code bellow:

upload attachments method

I am currently working to resolve this issue, any assistance or information from people who have encountered this issue before will be appreciated.

Thank you for your feedback!


Unfortunately there is no batch API in SP PNP. Yet your task looks to be achievable with the use of standard Promise.all functionality. Yep, there will be numerous physical requests, yet the script can be pretty straightforward like:

var itemPnp = $pnp.sp.web.getList('/sites/dev01/Lists/Custom02').items.getById(101);

var promises = [
  itemPnp.attachmentFiles.add('Attachment 01.txt', 'Content123'),
  itemPnp.attachmentFiles.add('Attachment 02.txt', 'Content234'),
  itemPnp.attachmentFiles.add('Attachment 03.txt', 'Content567'),
  itemPnp.attachmentFiles.add('Attachment 04.txt', 'Content789')

Promise.all(promises).then(function(results) {

You need to add files to array of promises & then use Promise.all and pass one by one promise.

You need to do something like below:

let files = [{
    name: "File5.txt",
    content: "balh"
}, {
    name: "File6.txt",
    content: "balh"
}, {
    name: "File7.txt",
    content: "balh"
}, {
    name: "File8.txt",
    content: "balh"

pnp.sp.web.lists.getByTitle("ChoiceFieldList").items.getById(1).attachmentFiles.addMultiple(files).then(_ => {

    pnp.sp.web.lists.getByTitle("ChoiceFieldList").items.getById(1).attachmentFiles.get().then(files => {

| improve this answer | |
  • Hi Hardik, It looks like you have proposed two different solutions here, one where you create your own promise chaining and one where you use the add Multiple could you please explain to me which one you recommend? – Yeti Byte Dec 19 '18 at 11:56
  • I would recommend you to try first approach – Hardik Dec 19 '18 at 12:00
  • Did you tried any approach? Did that work for you? – Hardik Dec 28 '18 at 6:54
  • I have tried, but still error for me. @YetiByte what solution you found? – Mihir Oct 1 '19 at 14:12

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.