@backpack/amazon-s3
️ 📦
Utilities for interacting with Amazon S3.
Installing
First, ensure you have set up Nexus as private registry needed to use Backpack.
Then, install the package using npm:
bash
npm install @backpack/amazon-s3
Make sure to also install the following AWS SDK client:
bash
npm install @aws-sdk/client-s3
S3Service
Utility class to get, put or delete objects from an Amazon S3 bucket.
ts
import { S3Client } from "@aws-sdk/client-s3";
import { S3Service } from "@backpack/amazon-s3";
const client = new S3Client();
const service = new S3Service(client, "my-bucket-name");
// puts an object
await service.putObject("your/object.json", "...");
// retrieves the object as text
const myObjectAsText = await service.getObject("your/object.json", {
type: "text",
});
// retrieves the object as json
const myObjectAsJson = await service.getObject("your/object.json", {
type: "json",
});
// retrieves the object as buffer
const myObjectAsBuffer = await service.getObject("your/object.json", {
type: "buffer",
});
// deletes the object
await service.deleteObject("your/object.json");