1 nodejs with Seaweed S3
Ignatiev Mikhail edited this page 2022-09-07 15:06:27 +03:00

Requirements & features

  • Use node@12.0.0+
  • Code with javascript or typescript
  • Seaweedfs with -s3 running at :8333

Installation

Install AWS S3 client

npm i @aws-sdk/client-s3

Client initialization

import { S3Client } from "@aws-sdk/client-s3"

const s3client = new S3Client({
  // specify endpoint with http://hostname:port
  endpoint: `http://127.0.0.1:8333`,
  // specify region since it is mandatory, but it will be ignored by seaweedfs
  region: `us-east-1`, 
  // force path style for compatibility reasons
  forcePathStyle: true,
  // credentials is mandatory and s3 authorization should be enabled with `s3.configure`
  credentials: {
    accessKeyId: `same as -accesskey`,
    secretAccessKey: `same as -secretkey`,
  }
})

Execute commands

// List buckets example
import { ListBucketsCommand } from "@aws-sdk/client-s3"
const response = await s3client.send(new ListBucketsCommand({}))
console.log(response.Buckets)

More commands: API Reference