I recently saw a post on the Microsoft Tech Community where an issue was raised when trying to upload a large file into SharePoint and then move it using Flow. The initial Trigger was "When a file is created (properties only)" and the subsequent actions were all geared towards moving the file to another location.
The issue with this was that the move action would constantly error because the file was still uploading (especially if it was a large file) or it would notionally move mid-upload and so start causing 404s because the file no longer existed in that location.
The first thoughts for a solution was to place a delay action in, but how long do you delay for to allow a variety of different file sizes to be uploaded?
The solution to this was to make Flow understand when the file upload had completed, and this can be found by looking at the file being uploaded. During upload, the size of the file will always be set to 0, and won't change until the upload has completed and SharePoint can then assign the correct size value.
The way I achieved this was by using a variable called "File Uploaded" which is set to False by default. I then have a "Do Until" action which will get the latest properties from the file and check to see if the file size is greater than 0. The key thing to remember is that the loop will only run 60 times, therefore if I don't delay it, it will run once per second for 60 seconds which won't be enough time if I'm uploading a large file. Therefore I've included a "Delay" for XX seconds if the file size still isn't being reported. For the purpose of a demo I set it to 10 seconds, however for uploading a file which was 3GB in size I upped it to 30 seconds.
My Flow therefore looks like this:
Trigger and setting the variable
Checking to see if the size has changed from 0. If it has, then I will continue the process, by setting the "File Uploaded" variable to True and therefore breaking the loop.
Nice and simple, yet effective to ensure that your upload operation has completed before processing.
The issue with this was that the move action would constantly error because the file was still uploading (especially if it was a large file) or it would notionally move mid-upload and so start causing 404s because the file no longer existed in that location.
The first thoughts for a solution was to place a delay action in, but how long do you delay for to allow a variety of different file sizes to be uploaded?
The solution to this was to make Flow understand when the file upload had completed, and this can be found by looking at the file being uploaded. During upload, the size of the file will always be set to 0, and won't change until the upload has completed and SharePoint can then assign the correct size value.
The way I achieved this was by using a variable called "File Uploaded" which is set to False by default. I then have a "Do Until" action which will get the latest properties from the file and check to see if the file size is greater than 0. The key thing to remember is that the loop will only run 60 times, therefore if I don't delay it, it will run once per second for 60 seconds which won't be enough time if I'm uploading a large file. Therefore I've included a "Delay" for XX seconds if the file size still isn't being reported. For the purpose of a demo I set it to 10 seconds, however for uploading a file which was 3GB in size I upped it to 30 seconds.
My Flow therefore looks like this:
Trigger and setting the variable
Checking to see if the size has changed from 0. If it has, then I will continue the process, by setting the "File Uploaded" variable to True and therefore breaking the loop.
Nice and simple, yet effective to ensure that your upload operation has completed before processing.
This is genius, thanks for the guide, helped prevent my flows from running into write conflicts when updating file properties
ReplyDelete