File Loader Time Out - Saving to Dropbox

Getting ready to have a developer help with a function to upload large video files using the file uploader which then saves the files to Dropbox. Want to make sure I have a path that is even possible within Anvil before I commit.

The app is basically a form to submit videos to a subscription based video platform which has native integration with Dropbox. The form collects the metadata which we save to a database, and they add the files which will pass to our Dropbox via the Dropbox API in a server module.

Currently upon “submit” we are just redirecting to custom upload page (“File Requests”) provided by Dropbox which is disconnected from our app. We like the idea of using the file loader because it will give us the ability to rename files and make it easier to match the uploads with form submissions.

The main issue I have is the server timeout. The large video files are going to take longer than 30 seconds to upload.

I thought I could get around this by moving the upload API to a background task . . . but . . . still getting a server time out. Presumably because the background task needs launched from another server call?

I have recreated in this app.
https://anvil.works/build#clone:I47YOW2RGEF5BKBJ=H7ZODBUSNYRVTY5UFYDFXMRU
The server module has both the standard and background task attempts. I switch between them on form.

** You will need to modify slightly for this to work for you.
1. Add your Dropbox api key the dbx_personal secret
2. add dbx_path folder to your Dropbox or change to a path that does exist

Uploading works fine with both regular and background task when using small test .txt files. Both received timeouts when trying on a 45MB video file.

Any Ideas on how to make this work?

I have read this article: Timeout on large file upload - #2 by owen.campbell
Not sure I totally understand, looking at the code might help clarify but the open in Anvil link is now invalid.
Could I use a table to temporarily hold the media files and use a background task to transfer to Dropbox?

Any help would be greatly appreciated.

1 Like

Sorry, I deleted that example app by mistake.

It’s not clear to me why the files need to sent to the anvil server. Why can’t they just be sent directly from the browser to Dropbox (with only the meta data going to a data table)?

(although I can’t clone your app right now to look as I only have a phone available, so my apologies if that would have made it obvious).

At a guess, it’s because the Dropbox python API is available server side, which makes it easy to write the upload code. However, that’s introducing a transfer to the anvil server, which may not be necessary at all.

1 Like

Very interested in the solution to this one!!

Yes on the Dropbox SDK being available in a sever module.

Guessing the alternative would be to implement in Javascript but this is not accessing the users Dropbox but rather a "corporate’ Dropbox. How could the API key be securely transmitted to the client?

Well, if you have a developer lined up, perhaps you should ask them how they intend to approach the problem.

If it were me, I’d probably look at using anvil’s http module and the dropbox REST API.

(And, speaking as a freelancer myself, I’d have told you that before signing up to take on the job).

It’s twice removed, but here’s a post where I put sample code that I created using Owen’s no longer available example on how to avoid the file upload timeout: File upload timeout - #2 by jshaffstall

1 Like

Right on, looks like http module may work. I will work out a little test to confirm. I have not even presented the scope to them yet. It is a local dev firm who is not familiar with Anvil so doing my homework before having them even scope.

I’m just an accountant/analyst who is picking up a little coding. Been able to figure out everything myself so far. Loving the platform, it is just the right amount of stretch from my current skillset!

** Any comment on passing the API key stored as a secret to the client to use with the http module?

You might find Pkce of use here.

Much thanks, bit over my head but I get the gist. Solves my primary question of whether there is a way to get it done before I embark.:grinning:

Also experimenting within the Dropbox app to just generate a unique key scoped to each instructors folder. Method may still be vulnerable but if such a restrictive key gets in the wild not a massive concern.

Really appreciate the input, I will post back what the final is for the community.