Created
November 15, 2021 11:18
-
-
Save jameshfisher/5a5e39380b9a3440334f610a92587209 to your computer and use it in GitHub Desktop.
Using Digital Ocean Spaces with S3 client in NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3'; | |
const s3AccessKeyId = "Y64W56U7IE85W46JH"; // Generate key at https://cloud.digitalocean.com/account/api/tokens | |
const s3SecretAccessKey = "y546wu7ie5u435y/7uei564sy5u6w57"; | |
const s3Bucket = "foo"; // Assumes your Space is https://cloud.digitalocean.com/spaces/foo | |
const s3Region = "nyc3"; // Get this from "Endpoint" at https://cloud.digitalocean.com/spaces/foo/settings | |
const s3Endpoint = "https://nyc3.digitaloceanspaces.com"; // From "Endpoint" at https://cloud.digitalocean.com/spaces/foo/settings, prepend 'https://' | |
const s3Client = new S3Client({ | |
endpoint: s3Endpoint, | |
region: s3Region, | |
credentials: { | |
accessKeyId: s3AccessKeyId, | |
secretAccessKey: s3SecretAccessKey, | |
}, | |
}); | |
const resp = await s3Client.send( | |
new PutObjectCommand({ | |
Bucket: s3Bucket, | |
Key: "my test key", | |
Body: "my test body", | |
}), | |
); | |
console.log(JSON.stringify(resp.$metadata)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment