How to use the return value from FilePicker to add to a SharePoint list item attachment, using @pnp

%3CLINGO-SUB%20id%3D%22lingo-sub-1856144%22%20slang%3D%22en-US%22%3EHow%20to%20use%20the%20return%20value%20from%20FilePicker%20to%20add%20to%20a%20SharePoint%20list%20item%20attachment%2C%20using%20%40pnp%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1856144%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EI'm%20getting%20this%20error%20when%20using%20the%20below%20to%20submit%20to%20a%20SharePoint%20list%20item%20as%20an%20attachment.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22234.PNG%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F231601i731AED35AA3D1E9A%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22234.PNG%22%20alt%3D%22234.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EI'm%20using%20this%20method%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Econst%20%7B%20filePicked%20%7D%20%3D%20this.state%3B%0A%20%20%20%20%20%20%0A%20%20if%20(filePicked)%20%7B%0A%20%20%20%20let%20targetList%3A%20IList%20%3D%20sp.web.lists.getByTitle('PanelMeetings')%3B%0A%20%20%20%20let%20selectedFile%20%3D%20filePicked.downloadFileContent()%3B%0A%0A%20%20%20%20let%20reader%20%3D%20new%20FileReader()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20reader.readAsArrayBuffer(selectedFile)%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20reader.onload%20%3D%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20targetList.items.getById(r.data.Id).attachmentFiles.add(filePicked.fileName%2C%20reader.result)%3B%0A%20%20%20%20%20%20%20this.setState(%7B%0A%20%20%20%20%20%20%20%20%20message%3A%20'Attachment%20Successfully%20added'%0A%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI've%20read%20this%3A%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fen.it1352.com%2Farticle%2Ffe83588ba22a46fa8c16676cc29ec66a.html%22%20rel%3D%22nofollow%20noreferrer%20noopener%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fen.it1352.com%2Farticle%2Ffe83588ba22a46fa8c16676cc29ec66a.html%3C%2FA%3E%3CSPAN%3E%26nbsp%3BBut%20it's%20not%20detailing%20the%20exact%20problem%20comprehensively%20enough.%20Can%20someone%20tell%20me%20what%20I'm%20doing%20wrong%20here%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1856144%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Contributor

I'm getting this error when using the below to submit to a SharePoint list item as an attachment.

234.PNG

I'm using this method:

 

const { filePicked } = this.state;
      
  if (filePicked) {
    let targetList: IList = sp.web.lists.getByTitle('PanelMeetings');
    let selectedFile = filePicked.downloadFileContent();

    let reader = new FileReader();
                   
     reader.readAsArrayBuffer(selectedFile);
        
     reader.onload = () => {
        
           targetList.items.getById(r.data.Id).attachmentFiles.add(filePicked.fileName, reader.result);
       this.setState({
         message: 'Attachment Successfully added'
         });
         };
        }

 

I've read this: https://en.it1352.com/article/fe83588ba22a46fa8c16676cc29ec66a.html But it's not detailing the exact problem comprehensively enough. Can someone tell me what I'm doing wrong here?

 

0 Replies