New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background uploading #237

Closed
richardwillars opened this Issue Jun 28, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@richardwillars
Copy link
Contributor

richardwillars commented Jun 28, 2017

On a project I'm working on there's a requirement for uploading to continue even if the user refreshes the page or navigates away from it to another section of the website (another react app for example). Investigated a lot of different solutions and almost all of them don't work due to browser security, but I managed to get a proof of concept working using service workers.

Demo: https://www.dropbox.com/s/smblm2w342atu6y/background%20uploading.mov?dl=0

It essentially uses a service worker to store a file list, then when a page loads it asks the service worker for that file list and pipes it into uppy. Uppy then detects which files are uploaded, partially uploaded etc and carries on as before. I did have a go at moving uppy into the service worker but I hit loads of problems with the tus client as it requires window.btoa etc which aren't available within a service worker.

https://gist.github.com/richardwillars/3a70b506bc410b6cde492421ed9e675b

To use:
import uppyService from './uppyService';
uppyService.initialise();
// Add files to uppy using uppyService.addFile(file)

You'll also need to have uppyServiceWorker.js on the page and you'd probably want to modify the endpoints within uppyService.js

As I said it's a complete proof of concept so nothing is configurable etc, and there's no way to destroy the worker (probably on upload completion). Would probably also only want to create the service worker when files start to get uploaded.

Either way, it's here if anyone wants it. If anyone improves it etc please share - this might be good as an Uppy plugin.

Any questions let me know!

@arturi

This comment has been minimized.

Copy link
Collaborator

arturi commented Aug 19, 2017

Closing in favor of #268. Thanks so much again, @richardwillars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment