flowjs / flow.js

A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API.
Other
2.96k stars 346 forks source link

Make async call per file before upload #247

Closed dukhevych closed 6 years ago

dukhevych commented 6 years ago

I need to make async calls to prepare upload for every file (in response i get file's targetUrl, also this call is used to validate user's quota for files uploading).

Is it possible?

Purpose is to start upload of every file which got targetUrl from async call. If I want to upload 1000 files, i don't want to wait for all prepare upload async calls, because it may take a very long time.

I tried to return Promise in target property of a flow object, but it didn't work.

dukhevych commented 6 years ago

Has anyone looked into this? Guys? Hello?

AidasK commented 6 years ago

There is a closed issue for this. You just have to find it. I think you have to add it to flow js only then it is valid but I can't remember for sure.

djechelon commented 6 years ago

Is there any reference to the other issue? I have the same requirement and want to know how to proceed.

Add file --> POST /targetUrl/{flowIdentifier}/init (size: xxx, totalChunks: yyy.....) If succeeds then add file to $flow If fail display an error message (e.g. extension mismatch, server out of disk space, etc)

psomashekar commented 5 years ago

I did this by generating the pre-signed url in flow.on('fileAdded', file => ..... and had my ajax call in there. After that, I added a key to the file object called uploadUrl. Then, I put a simple resolver function in the target in the flow config. For each file, this target is called, and the function, just returns uploadUrl for the individual file object, thereby enabling you to send different files to different pre-signed urls.