Node.js Backblaze B2 存储服务库
A customizable B2 client for Node.js:
axios and axiosOverride config arguments) and at the global level (see axios config argument at instantiation) so you can use any axios feature.retries argument at instantiation.This library uses promises, so all actions on a B2 instance return a promise in the following pattern:
b2.instanceFunction(arg1, arg2).then(
successFn(response) { ... },
errorFn(err) { ... }
);const B2 = require('backblaze-b2');
const b2 = new B2({
applicationKeyId: 'applicationKeyId', // or accountId: 'accountId'
applicationKey: 'applicationKey' // or masterApplicationKey
});
async function GetBucket() {
try {
await b2.authorize(); // must authorize first (authorization lasts 24 hrs)
let response = await b2.getBucket({ bucketName: 'my-bucket' });
console.log(response.data);
} catch (err) {
console.log('Error getting bucket:', err);
}
}Each request returns an object with:
status - int, html error StatusstatusTextheadersconfigrequestdata - actual returned data from backblaze, https://www.backblaze.com/b2/docs/calling.htmlEach action (see reference below) takes arguments and constructs an axios request. You can add additional axios options at the request level using:
axios argument (object): each property in this object is added to the axios request object only if it does not conflict with an existing property.axiosOverride argument (object): each property in this object is added to the axios request object by overriding conflicting properties, if any. Don't use this unless you know what you're doing!axios and axiosOverride work by recursively merging properties, so if you pass axios: { headers: { 'your-custom-header': 'header-value' } }, the entire headers object will not be overridden - each header property (your-custom-header) will be compared.…If an upload is interrupted, the fileId can be used to get a list of parts
which have already been transmitted. You can then send the remaining
parts before finally calling b2.finishLargeFile().
let response = await b2.listParts({
fileId,
startPartNumber: 0,
maxPartCount: 1000
})See the CHANGELOG for a history of updates.
For this update, we've switched the back end HTTP request library from request to axios as it has better Promise and progress support built in. However, there are a couple changes that will break your code and ruin your day. Here are the changes:
res), this data now resides in res.data.then(). Because we are no longer using the same promise library, this functionality has been removed. However, progress reporting is still available by passing a callback function into the b2.method() that you're calling. See the documentation below for details.b2.downloadFileById() accepted a fileId parameter as a String or Number. As of 1.0.0, the first parameter is now expected to be a plain Object of arguments.Contributions, suggestions, and questions are welcome. Please review the contributing guidelines for details.
暂无开放 Issues,或尚未同步最近议题。