e.g. with npm
npm install --save aws-sdk
import S3 from "aws-sdk/clients/s3";
const accessKeyId = "access key here";
const secretAccessKey = "secret access key here";
const endpoint = "https://gateway.tardigradeshare.io";
const s3 = new S3({
accessKeyId,
secretAccessKey,
endpoint,
s3ForcePathStyle: true,
signatureVersion: "v4",
connectTimeout: 0,
httpOptions: { timeout: 0 }
});
(async () => {
const { Buckets } = await s3.listBuckets({}).promise();
console.log(Buckets);
})();
(async () => {
// `file` can be a readable stream in node or a `Blob` in the browser
const params = {
Bucket: "my-bucket",
Key: "my-object",
Body: file
};
await s3.upload(params, {
partSize: 64 * 1024 * 1024
}).promise();
})();
The getSignedUrl
function creates a cryptographically signed url. No contact with the gateway is needed here; this happens instantaneously.
const params = {
Bucket: "my-bucket",
Key: "my-object"
}
const url = s3.getSignedUrl("getObject", params);
// e.g. create an <img> where src points to url