Skip to content

Instantly share code, notes, and snippets.

@phillipharding
Created January 23, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipharding/d2d8af05fe00cc2b9e60f56896b082bd to your computer and use it in GitHub Desktop.
Save phillipharding/d2d8af05fe00cc2b9e60f56896b082bd to your computer and use it in GitHub Desktop.
public async uploadFileToSharePoint(documentLibrary: string, webUrl: string, fileName: string, fileB64: any): Promise <any> {
try {
const web = new Web(webUrl);
documentLibrary = documentLibrary.replace(location.origin, "");
console.log(documentLibrary);
/* const rs: FileAddResult = await web.getFolderByServerRelativeUrl(documentLibrary).files.add(fileName,fileB64,true); */
const rs: FileAddResult = await web.getFolderByServerRelativeUrl(documentLibrary)
.files.addChunked(
fileName,
fileB64,
(data: ChunkedFileUploadProgressData) => {
console.log(`File Upload chunked: ${(data.currentPointer / data.fileSize)}%`);
return data.currentPointer / data.fileSize;
},
true
);
return rs;
} catch (error) {
console.log(error);
}
}