I want to update the list item with attachment but not sure why its failing the payload while saving it.

try {
 sp.web.lists.getByTitle(listName).items.select(item.Title).add((r => {
 // this will add an attachment to the item we just created to push t sharepoint list
 r.item.attachmentFiles.add(this.state.UploadedFilesArray.name, this.state.UploadedFilesArray).then(result=>{
} catch(e){

2 Answers 2


There is an error in this code:


Correct way:


You don't even need .select("Title") part. You are creating list item. thereis no point in selecting columns here. keep it simple like so:


I don't think this syntax is correct. It's unclear what you are doing here:

.add((r => {..)

items.add method adds list item. this is the right syntax:

.items.add({Title: 'New List item'})

Then, to add an attachment you can do it like so:

  let newListItem = await sp.web.lists.getByTitle("CustomList").items.add({Title: 'new Item'});
  await newListItem.item.attachmentFiles.add("file.txt","Some content");

Or, if you can't use async/awayt, do it like so:

  sp.web.lists.getByTitle("CustomList").items.add({ Title: 'new Item 2' }).then(newListItem => {
    newListItem.item.attachmentFiles.add("file.txt", "Some content");


If you want to select an existing list item by id:

let item = sp.web.lists.getByTitle("CustomList").items.getById(1);
item.attachmentFiles.add("file.txt", "Some content");

If you need to get list items by Title and add attachments to these items:

let item = sp.web.lists.getByTitle("CustomList").items.filter("Title eq 5").getAll().then(items => {
    for (var i = 0; i < items.length; i++) {

      let currentItem = sp.web.lists.getByTitle("CustomList").items.getById(items[i].Id);
      currentItem.attachmentFiles.add("file 2.txt", "Some content 2");

I was using SP Editor Chrome extension for debugging this script:

enter image description here


You could add attachment to a list item through below PowerShell.

#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$ListName = "Projects"
$ItemID ="2"
$FilePath ="C:\Docs\UserInfo.csv"
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the List Item
$Item  = Get-PnPListItem -List $ListName -Id $ItemID
#Get the File and Add to List Item Attachment
$FileStream = New-Object IO.FileStream($FilePath,[System.IO.FileMode]::Open)
$AttachmentInfo = New-Object -TypeName 
$AttachmentInfo.FileName =  Split-Path $FilePath -Leaf
$AttachmentInfo.ContentStream = $FileStream
$AttchedFile = $Item.AttachmentFiles.Add($AttachmentInfo)

Reference:Add Attachment to List Item using PowerShell


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.