Vydia / react-native-background-upload

Upload files in your React Native app even while it's backgrounded. Supports Android and iOS, including camera roll assets.
MIT License
730 stars 333 forks source link

Multiple file uploads causes multiple notifications. #286

Open YassinEldeeb opened 3 years ago

YassinEldeeb commented 3 years ago

Is there a way to upload multiple files and only get a single notification for the uploading progress of them all together or just remove all of the notifications.

cause that is a very terrible user experience

Screenshot_2021-09-09-05-12-13-13_ea9ea7d046c1634ca33ae27306ec1f83

kfitzsimons commented 3 years ago

Experiencing the same issue, any solution?

augini commented 3 years ago

I also have the same issue and I am about to implement the uploads using a background queue rather than uploading the videos concurrently.

YassinEldeeb commented 3 years ago

I just throw that package out of my project, and used expo-file-system, It uploads files in the background and you can have multiple concurrent uploads, but it doesn't have progress notification, you can implement a notification using expo-notifications (I think it's the easiest and pretty good too) and just make it sticky and say whatever your message like "Uploading..." and store that notification Id so that when all of your uploads are done clear that notification using it's id

-- Don't implement the uploads using a background queue, It will be very slow, I think the only tradeoff when using my solution over this package is that you can't add that progress bar to the notification, but honestly it's not of a crucial feature cause it's just a progress bar and you can get the files count and just whenever an upload is done increment the uploaded files count and update the notification message to be like "2/3 Files Uploaded" very easily and that will support very low grad devices rather than the progress bar that supports only Android version < 8.0.

Links to Follow: Expo Filesystem -> https://docs.expo.dev/versions/latest/sdk/filesystem/#filesystemuploadasyncurl-fileuri-options P.S: remember to set the sessionType to FileSystemSessionType.BACKGROUND

Expo Notifications -> https://docs.expo.dev/versions/latest/sdk/notifications/

hope I helped.

YassinEldeeb commented 3 years ago

If anyone have the time and want to build the best solution ever, make your own native modules with Java and Swift.

I came across this article where he builds an Unstoppable Service that means you restart your device it starts even you didn't open the app, you close the app it's still running, you lost internet connection you retry, basically there's a very very tiny chance of upload failing using that solution.

I've built my own using Java by the help of this article and other random resources, then used the first solution above cause I was pretty tired and I spent too much time making it for android and there's also IOS that will take me a lot of time,

https://medium.com/reactbrasil/how-to-create-an-unstoppable-service-in-react-native-using-headless-js-93656b6fd5d1

SymntxHomendra51 commented 2 years ago

Those who want to use a different library. You can use this https://github.com/Rapsssito/react-native-background-actions instead. But you will need to use Axios or fetch API to make the upload and some custom code to have some freedom.

YassinEldeeb commented 2 years ago

That's cool @SymntxHomendra51. Thanks!

YashGupta61969 commented 1 year ago

Can you show me the code ? I need to implement same functionality.