Hi! So I have the following problem. The user selects multiple files with file_picker package. I convert this to a List<InputFile> to upload it to appwrite bucket. But the Flutter SDK only provides "createFile", which means uploading only one file at a time. I don't feel like it's a good approach to just iterate over the List<InputFile> with a for-loop and upload each at once, because this drastically increases the server requests. Is there any better way to do this?
You can do future.wait . Then all the requests would be make concurrent
But if you are talking about an endpoint which which upload multiple files through single request, its not there
Maybe create an issue and explain your use case
Okay, thank you, will do that!
Yeah, that's what I initially meant. But I think Future.wait will also work. Thanks!
hey guys. I'm also looking for something similar. but i'm not a flutter developer. so dunno what Future.wait means. can you please explain what it does
I think the equivalent would be using async/await with Promise.all() in JS
Then afaik it'll only send all the requests at once without waiting for the other request to complete. which doesn't really decrease the total number of server requests. also, we cannot terminate the whole process if any of the file fails to upload
I don't think there would be a way to decrease the number of requests at the minute anyway without a new endpoint, the best that can be done would be to try to do them concurrently to reduce the time it takes to get through them all? It doesn't sound like the files being uploaded would depend on any of the other uploads
yeah, that's also true. appwrite should consider developing batch uploads similar to Firebase. And about dependent uploads. I'm not talking about the files being dependent on any other uploads. Let's say we have 3 files to upload. file_1 uploaded successfully, but while uploading file_2, maybe we got some network issues and the process failed. so now how do we know that file_2 upload failed? and also, what if we want to terminate the whole uploading process because we'll need to store the file download links in a doc? we obviously don't want to store links for files that don't exist
If you want to be able to tell if any of the uploads failed, take a look at Promise.allSettled(). It returns an array of the responses as well as the status of the requests so you'd be able to go through and check which of the uploads failed. With terminating the upload process, what scenarios would it be where the process needs to be terminated? Just want to make sure I understand a bit better
let's consider post creation in a social media app. the user can upload multiple files also with some texts. so if any of the files fail to upload, we don't want the post to be created in our doc. also we don't want to keep the files that were uploaded successfully in our storage. in simpler words, terminating the whole process
Ah I see, so if one of the uploads fails, it would still return the $id
of the successful uploads so I'd do a check through the files to see if any failed and if they did then go back through and use storage.deleteFile()
to delete them from the bucket? As far as I can tell, that would be the best approach to take
yeah as far as the current appwrite implementation. but if we think in general, idt it's so much of the best approach to follow. If the user uploads hundreds of files, and only one fails; i mean, the bandwidth cost is too high just for a single failure. I used to use firebase back then. and afaik, when we do a batch upload, they stack the successful uploads until all the uploads are completed. and only if everything goes well, they write the changes to the db. otherwise, don't
I remember batch uploads was in discussion. @manazo you can look at our GitHub issues if there exists an issue about it and upvote, if not, feel free to open an new issue
Just checked. There is an open issue covering this topic
Bit late to the party, but yeah, that's the exact problem I was having which Pratik showed with his social media example (except it wasn't for social media)
And yeah, it increases server requests
Recommended threads
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...
- [SOLVED] OAuth With Google & Flutter
Hi all, I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutte...