Uploading a large file to SharePoint: Corrupted file in destination folder when upload loop is interrupted

Viewed 161

I am trying to upload a large file to SharePoint site using the code described in the below example from Microsoft: https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/upload-large-files-sample-app-for-sharepoint

It works great and I am able to upload the file with no errors. But I noticed that the file is being created (or overwritten if already exists) in the SharePoint destination folder immediately once the upload loop starts, and before the FinishUpload() is being called.

While as per Microsoft documentation, the file in the destination folder is not being changed until FinishUpload() is called:

File.FinishUpload method

"Uploads the last file fragment and commits the file. The current file content is changed when this method completes."

What actually happens with me is that if the upload loop has been interrupted for any reason, I find a corrupted file in the destination folder.

Any ideas how I can prevent updating the destination folder until FinishUpload() is being called?

0 Answers
Related