2 nodejs with Seaweed S3
Ignatiev Mikhail edited this page 2025-04-04 11:07:49 +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,
  // dual stack endpoint is not supported by seaweed
  useDualstackEndpoint: false,
  // checksum validation should be disabled, overwise `x-amz-checksum` will be injected directly into files
  responseChecksumValidation: `WHEN_REQUIRED`,
  requestChecksumCalculation: 'WHEN_REQUIRED',
  // 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