Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Created May 19, 2024 03:03
Show Gist options
  • Save crazy4groovy/12b58d5caa827e0de52615175b00fabe to your computer and use it in GitHub Desktop.
Save crazy4groovy/12b58d5caa827e0de52615175b00fabe to your computer and use it in GitHub Desktop.
A simple BackBlaze (B2) E3 compatible file uploader (JavaScript)
// SEE: https://github.com/yakovkhalinsky/backblaze-b2/issues/118
import {
S3Client,
PutObjectCommand,
// S3ClientConfig,
// DeleteObjectCommand,
} from "@aws-sdk/client-s3";
const region = process.env.B2_REGION;
const b2Client = new S3Client({
region,
endpoint: `https://s3.${region}.backblazeb2.com`,
maxAttempts: 3,
credentials: {
// Must have both read & write permissions on process.env.B2_BUCKET_NAME
accessKeyId: process.env.B2_ID,
secretAccessKey: process.env.B2_KEY,
},
});
export async function send(ContentType="image/jpg", opts /*: PutObjectCommand*/) {
return b2Client.send(
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/putobjectcommandinput.html
new PutObjectCommand({ ContentType, ...opts })
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment