SPFx: Error adding O365 document with properties to SharePoint online library

18 views Asked by At

I've created an SPFx WebPart (React/TypeScript/PNPJs) that at one point uploads documents to a SharePoint Online Document Library. The code for the upload of one file is roughly as follows:

if (file.size <= MAX_UPLOAD_SIZE) { // MAX_UPLOAD_SIZE is 1M
  uploadPromise = files.addUsingPath(name, file, {Overwrite: true});
}
else {
  uploadPromise = files.addChunked(name, file, progressHandler, true);
}

const result = await uploadPromise;

The problem is as follows:

  • Assume the document is an Office 365 document.
  • Assume it was downloaded from a different SharePoint Online Site document library
  • Assume the original document library contained a lookup field
  • Assume the target document library does not contain such a field or the value selected is not present in the target site's lookup list

Then the upload will fail with an exception. So how can I upload documents containing SharePoint Online properties without those properties causing an error?

1

There are 1 answers

0
RaytheonXie-MSFT On

Ensure that the user or service principal used to interact with SharePoint Online has the necessary permissions to add documents to the library and set properties. This includes permissions like Add Items, Edit Items, and Manage Lists on the target library.