Browser upload to Backblaze b2
Today, I released another piece of software under the MIT license. This time, it is to allow web users to securely upload files directly to a b2 bucket.
The b2 api is reasonably nice, although it has 1 major problem – tokens for small file uploads are not secure in a way that would allow them to be passed back to the client.
I started with resumable.js. We've been using a modified version of this to handle large media uploads for a few years now. It's a simple, relatively clean bit of code without any major external dependencies. We had to make a few changes to resumable.js to allow our extension to work.
The frontend is a set of callbacks for resumable.js to perform sha1 hashing, fetch tokens, alter upload addresses, etc.
The backend (written in PHP 7) handles authenticating end user upload requests and creating backblaze tokens. It also handles receiving small (up to 5MB) files from the end user and uploading them to b2. The only thing it uses that may not be in everyone's PHP stack is redis, which is optional but highly recommended for performance.
A work in progress...
- More testing
- Example page with upload progress reporting
- Better handling of error conditions / reporting back to resumable.js
- Multi-threaded uploads of large files (we do this on our previous custom version of resumable.js)