transloadit / uppy

The next open source file uploader for web browsers :dog:
https://uppy.io
MIT License
29.17k stars 2.01k forks source link

Allow streaming upload also for unknown length streams #5305

Open mifi opened 4 months ago

mifi commented 4 months ago

Initial checklist

Problem

Yes companion now streams most files without first storing them when setting COMPANION_STREAMING_UPLOAD=true, however it still downloads the whole file first when encountering a file of unknown length (missing content-length header): https://github.com/transloadit/uppy/blob/f4dd3d534ff4378f3a2f73fe327358bcbde74059/packages/%40uppy/companion/src/server/Uploader.js#L288

This happens because for some of the uploaders we need to know the size of the file before uploading. I know that this happens for the Google Drive plugin when uploading files from Google Docs (export). It can also happen if someone uses the URL plugin to download/upload a file which doesn't have a content-length.

This is problematic for large files (e.g. 100gb) because it requires a lot of storage space.

Solution

When using an uploader that supports it (tus, xhr/multipart, s3?) we can upload directly without knowing the size.

Alternatives

leave it

Acconut commented 4 months ago

Just repeating my comment to add more info for tus:

Companion does not even have to count the bytes on its own. You can pass tus-js-client a readable stream while enabling uploadLengthDeferred and setting chunkSize. Then it will count the bytes on its own and let the server know the size once the readable stream closed.

It's worth noting that this feature requires the tus server to support an optional extension. While most tus server provide this, it is not always the case. So maybe an option to disable this for tus uploads is helpful.

mifi commented 2 weeks ago

I just tested and it seems to be working! Will create a PR