SOLVED

Using Flow with SharePoint Library - file copy executed before file upload is complete

Copper Contributor

Trying to use Flow to move video files submitted to a "dead drop" folder into a controlled-access folder within a SharePoint Online document collection.

 

Essentially, a user drags a video file onto the dead drop (displayed in a browser) to initiate the upload and it gets whisked away into a locked down folder afterward. There is also an email alert that seems to be working fine.

 

The trigger When a file is created (properties only) fires when the upload starts, so the file isn't ready to be copied when the Flow starts. If I insert a static Delay that's long enough for the upload to complete, all is well.

 

The problem is my files are potentially a few GB in size and the upload time will be highly variable. If the Delay is too short, the remainder of the actions execute on the partially-uploaded file, with a BadRequest error.

  • If I try a simple Move file action in Flow, the action fails (status 404, "The file /path/to/file.example does not exist.") and the upload aborts as well.
  • If I try a Copy file action (to be followed by a Delete file action) with Asynchronous Pattern active and the Timeout set to 12h, the copy fails (status 400 "The system cannot find the file specified.")

 

I've tried testing the Modified property of the target file in a Do until loop, in the hope that the modification date and time are updated as the upload progresses and can thus be used as a progress counter - that's not working.

 

For the record, I've tried these other things with comparable results:

  • Using the When a file is created in a folder trigger
  • Setting Configure run after option in subsequent actions to ensure that the previous Copy File or Move file action was completed before moving ahead with the next action.

 

So is there any way to test to see if the uploaded file is "all there" after my When a file is created (properties only) trigger fires? Is there a property that gets applied only after the upload is complete that I can wait for or a better trigger to use to start the Flow? Is there just some better way to re-route large uploaded files into a locked-down folder?

3 Replies
best response confirmed by DPapandria (Copper Contributor)
Solution

Hi @DPapandria

 

The key indicator as to whether your file has uploaded or not is the file size. Until the upload is complete, the file size will be 0. As soon as it's complete you'll see the actual size. I tested this on a 400MB file.

 

So I have shaped a Flow to look like the following:

 

  1. Trigger - When a file is created (properties only)
  2. Action - Initialise variable: Created a boolean called FileUploaded and a default value of false
  3. Control - Do until: FileUploaded = true
    1. Action - Get file metadata (this has to be done each time to ensure that we're looking at a fresh set of data
    2. Condition - If Size (from get file metadata) is not equal to 0
      1. If Yes: Set Variable "FileUploaded" to true
      2. If No: Delay for 10 seconds
  4. Action: Move File

 

See my attached screenshot for an example.

 

The thing to remember is that the loop will only run through 60 iterations, so ensure that you select your delay to give your file enough time to upload.

 

Hope this helps.

That works perfectly.  Thanks very much!!

@Matt Weston 

I am trying to replicate this flow, the section i am stuck on is the "get file Metadata",

The is asking for a file identifier i have tried ID and name but this errors stating the file does not exist.

 

Can you let me know the values the get file metadata is expecting please?

 

1 best response

Accepted Solutions
best response confirmed by DPapandria (Copper Contributor)
Solution

Hi @DPapandria

 

The key indicator as to whether your file has uploaded or not is the file size. Until the upload is complete, the file size will be 0. As soon as it's complete you'll see the actual size. I tested this on a 400MB file.

 

So I have shaped a Flow to look like the following:

 

  1. Trigger - When a file is created (properties only)
  2. Action - Initialise variable: Created a boolean called FileUploaded and a default value of false
  3. Control - Do until: FileUploaded = true
    1. Action - Get file metadata (this has to be done each time to ensure that we're looking at a fresh set of data
    2. Condition - If Size (from get file metadata) is not equal to 0
      1. If Yes: Set Variable "FileUploaded" to true
      2. If No: Delay for 10 seconds
  4. Action: Move File

 

See my attached screenshot for an example.

 

The thing to remember is that the loop will only run through 60 iterations, so ensure that you select your delay to give your file enough time to upload.

 

Hope this helps.

View solution in original post