Edge

Storage

SDK Examples

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

JS JavaScript / TypeScript

Installation

npm install @aws-sdk/client-s3

Client Setup

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)
}

PY Python

Installation

pip install boto3

Client Setup

import boto3
import os

client = boto3.client(
    's3',
    endpoint_url='https://storage.edge.network',
    aws_access_key_id=os.environ['EDGE_ACCESS_KEY'],
    aws_secret_access_key=os.environ['EDGE_SECRET_KEY'],
    region_name='us-east-1'
)

Upload an Object

# Upload a file
client.upload_file('local-file.txt', 'my-bucket', 'remote-file.txt')

# Or upload bytes directly
client.put_object(
    Bucket='my-bucket',
    Key='hello.txt',
    Body=b'Hello, Edge Storage!'
)

Download an Object

# Download to file
client.download_file('my-bucket', 'remote-file.txt', 'local-file.txt')

# Or get bytes
response = client.get_object(Bucket='my-bucket', Key='hello.txt')
data = response['Body'].read()

List Objects

response = client.list_objects_v2(
    Bucket='my-bucket',
    Prefix='images/'
)

for obj in response.get('Contents', []):
    print(obj['Key'], obj['Size'])

GO Go

Installation

go get github.com/aws/aws-sdk-go-v2
go get github.com/aws/aws-sdk-go-v2/service/s3
go get github.com/aws/aws-sdk-go-v2/credentials

Client Setup

package main

import (
    "context"
    "os"
    
    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/credentials"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

func main() {
    cfg, _ := config.LoadDefaultConfig(context.TODO(),
        config.WithRegion("us-east-1"),
        config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
            os.Getenv("EDGE_ACCESS_KEY"),
            os.Getenv("EDGE_SECRET_KEY"),
            "",
        )),
    )
    
    client := s3.NewFromConfig(cfg, func(o *s3.Options) {
        o.BaseEndpoint = aws.String("https://storage.edge.network")
        o.UsePathStyle = true
    })
}

Upload an Object

_, err := client.PutObject(context.TODO(), &s3.PutObjectInput{
    Bucket: aws.String("my-bucket"),
    Key:    aws.String("hello.txt"),
    Body:   strings.NewReader("Hello, Edge Storage!"),
})

RB Ruby

Installation

gem install aws-sdk-s3

Client Setup & Usage

require 'aws-sdk-s3'

client = Aws::S3::Client.new(
  endpoint: 'https://storage.edge.network',
  region: 'us-east-1',
  force_path_style: true,
  access_key_id: ENV['EDGE_ACCESS_KEY'],
  secret_access_key: ENV['EDGE_SECRET_KEY']
)

# Upload
client.put_object(
  bucket: 'my-bucket',
  key: 'hello.txt',
  body: 'Hello, Edge Storage!'
)

# Download
response = client.get_object(bucket: 'my-bucket', key: 'hello.txt')
puts response.body.read

Common Configuration

Regardless of the SDK you use, you'll need these settings:

Setting Value Notes
endpoint https://storage.edge.network Required
region us-east-1 Use any valid region string
forcePathStyle true Required for Edge Storage