Skip to content
Docs

SDK examples

Edge Storage is fully compatible with AWS S3 SDKs. Use the official AWS SDK for your language with our endpoint.

The examples below use the official AWS SDKs for JavaScript and TypeScript, Python, Go and Ruby. Pick your language in each code block.

Install the SDK

npm install @aws-sdk/client-s3

Set up the client

import {
  S3Client,
  PutObjectCommand,
  GetObjectCommand,
  ListObjectsV2Command
} from '@aws-sdk/client-s3'

const client = new S3Client({
  endpoint: 'https://storage.edge.network',
  region: 'us-east-1',
  forcePathStyle: true,
  credentials: {
    accessKeyId: process.env.EDGE_ACCESS_KEY,
    secretAccessKey: process.env.EDGE_SECRET_KEY
  }
})

Upload an object

await client.send(new PutObjectCommand({
  Bucket: 'my-bucket',
  Key: 'images/photo.jpg',
  Body: fileBuffer,
  ContentType: 'image/jpeg'
}))

Download an object

const response = await client.send(new GetObjectCommand({
  Bucket: 'my-bucket',
  Key: 'images/photo.jpg'
}))

const body = await response.Body.transformToByteArray()

List objects

const response = await client.send(new ListObjectsV2Command({
  Bucket: 'my-bucket',
  Prefix: 'images/'
}))

for (const obj of response.Contents || []) {
  console.log(obj.Key, obj.Size)
}

Common configuration

Whichever SDK you use, you'll need these settings:

SettingValueNotes
endpointhttps://storage.edge.networkRequired
regionus-east-1Use any valid region string
forcePathStyletrueRequired for Edge Storage

Something unclear or out of date? Tell us, or read this page as Markdown.