GithubHelp home page GithubHelp logo

nodecraft / b2-cloud-storage Goto Github PK

View Code? Open in Web Editor NEW
42.0 5.0 10.0 952 KB

Backblaze B2 Cloud Storage API Client. Implements all of the B2 Cloud Storage APIs, with helper methods for uploading files.

License: MIT License

JavaScript 100.00%
backblaze b2 backblaze-b2 b2-cloud-storage hacktoberfest

b2-cloud-storage's Introduction

b2-cloud-storage

npm version dependencies Status Actions Status FOSSA Status

Backblaze B2 Cloud Storage API Client

b2-cloud-storage is an API wrapper for all current Backblaze B2 API operations. It provides helper methods for uploading files of all sizes, and takes care of the necessary chunking, parting, and API retries that need to happen to ensure files are uploaded successfully.

This module adheres the integration guidelines as published by Backblaze at https://www.backblaze.com/b2/docs/integration_checklist.html.

Basic Example

'use strict';
const b2CloudStorage = require('b2-cloud-storage');

const b2 = new b2CloudStorage({
	auth: {
		accountId: '<accountId>', // NOTE: This is the accountId unique to the key
		applicationKey: '<applicationKey>'
	}
});

b2.authorize(function(err){
	if(err){ throw err; }

	// this function wraps both a normal upload AND a large file upload
	b2.uploadFile('/path/to/file.zip', {
		bucketId: '<bucketId>',
		fileName: 'file.zip', // this is the object storage "key". Can include a full path
		contentType: 'application/zip',
		onUploadProgress: function(update){
			console.log(`Progress: ${update.percent}% (${update.bytesDispatched}/${update.bytesTotal}`);
			// output: Progress: 9% 9012/100024
		}
	}, function(err, results){
		// handle callback
	});
});

Documentation

You can read the full documentation here.

Roadmap:

  • Improve unit tests and code coverage
  • Add helper methods to delete all file versions for a single file
  • Add helper methods to better query paginated search

License

FOSSA Status

b2-cloud-storage's People

Contributors

captainyarb avatar cherry avatar dependabot[bot] avatar fossabot avatar greenkeeper[bot] avatar lclc98 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

b2-cloud-storage's Issues

Issues with both download file functions

There is a couple problems with the download file functions, currently writing unit tests and didn't want to combine the PR's. I will be making a PR to fix these

  • They require the downloadUrl from the authorize function but that isn't stored. This means apiUrl needs to be changed
  • They need to have appendPath set to false
  • Headers for downloadFileById aren't being set
  • data.url for request gets overridden

TypeError: url.URL is not a constructor

Hello, i'm using b2-cloud-storage npm package in my react-website,and run code like your Basic Example,but it's not work. how can i resolve this ? Thanks !

image

image

An in-range update of eslint-config-nodecraft is breaking the build 🚨

The devDependency eslint-config-nodecraft was updated from 2.0.1 to 2.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-config-nodecraft is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • Node 12 Test: There are 1 failures, 0 warnings, and 0 notices.
  • Node 10 Test: There are 2 failures, 0 warnings, and 0 notices.

Commits

The new version differs by commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of eslint-config-nodecraft is breaking the build 🚨

The devDependency eslint-config-nodecraft was updated from 1.7.4 to 1.7.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-config-nodecraft is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • Node 10 Test: There are 1 failures, 0 warnings, and 0 notices.
  • Node 8 Test: There are 1 failures, 0 warnings, and 0 notices.

Commits

The new version differs by 1 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Handle 503/service_unavailable errors

Occasionally when uploading files, even after an upload URL has been retrieved, B2 can respond with the following when attempting to upload:

{
  "code": "service_unavailable",
  "message": "c001_v0001113_t0035 is too busy",
  "status": 503
}

This is by design, and should trigger this library to attempt to get a new upload URL and retry.

We handle this more gracefully (-ish) in uploadFileSmall, but do not handle it at all in uploadFileLarge. For uploadFileSmall, we should be requesting a new upload URL on a retry, rather than just uploading again to the "too busy" URL. For uploadFileLarge, this check would would probably make sense around line 1402 of index.js, replacing the upload URL we just used and got an error from, with a new one.

Testing should be done as per https://www.backblaze.com/b2/docs/integration_checklist.html. A header can be set to simulate artificial errors.

No warning when non-authorized

If you perform an upload file request without authorization it returns a Javascript error rather than user error.

const config = {...};
const b2CloudStorage = require('b2-cloud-storage');
const b2 = new b2CloudStorage(config);
b2.uploadFile('filename', {...}, (err) => {...});

Error: TypeError: Cannot read property 'recommendedPartSize' of undefined.

Add support for Promises, with async/await

This library is pretty mature now and works really well, but still uses callbacks. There's nothing wrong with callbacks, but a lot of modern code nowadays uses promises via async/await, and having this library conform to that would be ideal.

Things to think about:

  • Should we bump a major version and just remove callbacks entirely?
  • Should we try to support both callbacks and promises?

b2_copy_file limited to 5GB

As per discussion with backblaze, b2_copy_file is limited to 5GB. We need add a helper method or similar to detect the file size, and then use b2_copy_part if necessary.

Drop dependency on `request`

request is now unmaintained. It still works really well and is actively used, but when we resolve #30, we should transition to something like node-fetch that uses promises.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.