question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add "smart" upload function

See original GitHub issue

The AWS S3 SDK for JavaScript has an upload function that does not correspond to any particular API request. You can give it a buffer or a stream, and it will automatically perform either a single PutObject call or a multi-part upload.

It would be a great benefit to this library to provide something similar. Right now, large file uploads are unnecessarily cumbersome, especially when the input is a stream. Authorization token management is a giant pain.

I am working on such a function right now for our own internal use. I’m writing it as a module that exposes a single function that can be attached to the prototype of the B2 class provided by this library (B2.prototype.uploadAny = require('backblaze-b2-upload-any');).

This issue is intended to convey my intent to integrate this function into this library and submit a PR. Therefore, I would very much appreciate any feedback on my proposal so that I can accommodate any necessary design changes as early as possible.

The current planned features of this function (many of which are already done) are:

  • Performs the upload using a single upload_file call or switches to a large-file upload as appropriate.
  • In large-file mode, uploads multiple parts with configurable concurrency.
  • Automatic management of upload tokens. An upload token (URL + authorization token) can be reused by future part uploads. Expired tokens (where the server returns 503 or 400) are discarded.
  • Automatic re-authorization if the server returns 401 in the middle of an upload.
  • Retry with exponential backoff.
  • Support for uploading:
    • Buffers
    • Streams
    • Local files (specified as a string path)
  • If the operation is aborted for whatever reason, any outstanding large-file upload is canceled with cancel_large_file.
  • The caller need not (and cannot) supply a hash. When uploading in large-file mode, a hash of the entire content is not provided to B2 – a hash is provided for each part. A caller-supplied hash of the content is therefore useless in large-file mode anyway.

There is a difference between the local file and stream cases. When uploading a local file, no content is buffered in memory. Rather, multiple read streams are created (and re-created as necessary if a part upload must be retried).

Stream support necessarily requires some buffering in memory to facilitate retries since node streams cannot be seeked (and not all stream types would be seekable, anyway).

Note that I currently introduce two new dependencies:

  • @hapi/joi which is used to validate the options object.
  • memoizee which is used during re-authorization. If multiple part uploads are trying to re-authorize at the same time, this prevents multiple authorize calls to B2.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:9

github_iconTop GitHub Comments

1reaction
odensccommented, Mar 6, 2020

@cdhowie Sorry for the delay, the API looks good but hopefully I can take a look at the code over the weekend.

1reaction
cdhowiecommented, Feb 18, 2020

The module is published. Feel free to leave code review comments here, or as issues on the module’s repository.

https://www.npmjs.com/package/@gideo-llc/backblaze-b2-upload-any

Read more comments on GitHub >

github_iconTop Results From Across the Web

Smart Upload Manager: Overview - Kantata Knowledge Base
The Smart Upload Manager is a tool designed to help automate the import of data from CSV files into Kantata OX. With SUM,...
Read more >
Smart Uploads in Gravity Forms - gravitymore
Gravity Forms smart Uploads Add-on allows you to limit the quantity and sizes of files that will be uploaded by your users. Single...
Read more >
Smart upload with folder merge - Firmex Knowledge Base
Smart Upload with Folder Merge allows you to upload folders and subfolders to Firmex multiple times without creating duplicates. When a folder is...
Read more >
About Smart Upload - SAS Help Center
The Smart Upload tool provides an automatic and easy way of setting up third-party creatives. With this tool, third-party tags are uploaded to...
Read more >
Create an Upload Workflow in Data Shuttle
Anyone with active Smartsheet license with any paid user role, internal permissions to use cloud drives where your data is located and Admin,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found