ExcelEverything
ExcelEverything

Reputation: 311

Move uploaded one-drive files automatically with power automate / flow

I have created a folder on onedrive and shared it with "anyone with the link", giving them all access to upload files.

As soon as the file is uploaded, I want a power-automate cloud flow to move the files to a secure location, out of reach from other users with the link.

I created the flow with 3 blocks "recurrence" (set to 5minutes), then trigger "when a file is created" (listening to said shared folder) followed lastly by "move or rename a file" (moving "file identifier" to destination "/secure/File name").

This works flawlessly with small files, but large files (assuming large enough to upload longer than the reoccurrence interval) fails and just stays put in the folder. A day of more later, I get an email alert "your operation has been throttled".

Is there a way to check that the input file has been fully uploaded first before attempting to move?

Ps. Initially I used the sharepoint version of these blocks, with similar results. Worst still, it would sometimes cause the upload to fail. I also used the create file > copy > delete method with similar issues like deleting it before its done uploading.

Upvotes: 0

Views: 3366

Answers (1)

ExcelEverything
ExcelEverything

Reputation: 311

If you are new to Power Automate like me - fair warning - its a bit of a @#$%.

Power Automate Quick primer:

Think of Power Automate as a drag n drop "script" of web server calls. Its not linear or even parallel programming. Its asynchronous polling of sorts. You have to decide if your flow will be manual ("instant"), automated or scheduled. TRIGGERS must go first. Instant will e.g. have a button trigger. Automated an event trigger (like a file was modified) and scheduled the Recurrence timer trigger. Kinda obvious but you cannot mix these triggers.

I tried to put the "when file modified" trigger after the Recurrence trigger in an effort to make the file modified trigger execute more regularly (which on the basic plans are only every 15min). This doesn't generate errors but results in very inconsistent behaviour.

Limits!

This brings me to limits. Be vary aware of the limits on your account type. The amount of API calls your flow can make per day varies from 1000 to 5000 for basic plans up to 20000. And also every action in your flow can count as such a call. If you plan to run a scheduled flow say every 1 minute of the day, and have four calls in that flow, you'll blow 5760 calls with a single running flow, and pretty quickly receive warning emails about being throttled.

The solution: how to move one-drive files automatically after upload?

Back to the problem at hand, I could run a simple automated flow (when file modified* > move or rename file) but that would only execute every 15 minutes. I opted for a scheduled flow (every 3 min) that would find all files in the folder and move it. I also filtered some files based on media type and didn't move if file size was still zero (indicating its still being uploaded), estimating about 10 actions per run. That's 480 runs per day and roughly 4800 actions or API calls in total per day, just under my 5000 limit. See the image below.

More limits and tips

  • *Onedrive calls have additional limits. Certain file actions carry the whole file contents with the action, limiting it to files < 50MB. For this reason avoid e.g. "When file created" and rather use "When file created (properties only)".
  • Watch your flow log. Sometimes a run can get stuck and consume your API request cap. You have to click it in the log and cancel the run.
  • You can set concurrency, time-outs and retry limits in the settings of each action/trigger. This can be very helpful to limit API calls.

File Drop Safe - Move from shared to private folder on schedule (template / example)

enter image description here

Upvotes: 0

Related Questions