Python and JavaScript SDKs
Any AWS S3 SDK works with Hive Buckets. Set three things: the endpoint, the region auto and path-style addressing. Keep your access key in environment variables:
export HIVE_BUCKETS_ENDPOINT=https://s3.dockhive.ioexport HIVE_BUCKETS_ACCESS_KEY_ID=DH...export HIVE_BUCKETS_SECRET_ACCESS_KEY=...Create a client
Section titled “Create a client”pip install boto3import osimport boto3from botocore.config import Config
s3 = boto3.client( "s3", endpoint_url=os.environ["HIVE_BUCKETS_ENDPOINT"], aws_access_key_id=os.environ["HIVE_BUCKETS_ACCESS_KEY_ID"], aws_secret_access_key=os.environ["HIVE_BUCKETS_SECRET_ACCESS_KEY"], region_name="auto", config=Config(signature_version="s3v4", s3={"addressing_style": "path"}),)npm install @aws-sdk/client-s3 @aws-sdk/lib-storage @aws-sdk/s3-request-presignerimport { S3Client } from '@aws-sdk/client-s3';
export const s3 = new S3Client({ endpoint: process.env.HIVE_BUCKETS_ENDPOINT, region: 'auto', forcePathStyle: true, credentials: { accessKeyId: process.env.HIVE_BUCKETS_ACCESS_KEY_ID, secretAccessKey: process.env.HIVE_BUCKETS_SECRET_ACCESS_KEY, },});Upload, download, list and delete
Section titled “Upload, download, list and delete”from boto3.s3.transfer import TransferConfig
BUCKET = "my-app-uploads"
# Small object from memorys3.put_object(Bucket=BUCKET, Key="notes/hello.txt", Body=b"hello", ContentType="text/plain")
# Any size file from disk: multipart is used automatically above the thresholdtransfer = TransferConfig(multipart_threshold=64 * 1024**2, multipart_chunksize=16 * 1024**2)s3.upload_file("video.mp4", BUCKET, "videos/video.mp4", Config=transfer)
# Downloadobj = s3.get_object(Bucket=BUCKET, Key="notes/hello.txt")print(obj["Body"].read())s3.download_file(BUCKET, "videos/video.mp4", "copy.mp4")
# List (paginated)for page in s3.get_paginator("list_objects_v2").paginate(Bucket=BUCKET, Prefix="videos/"): for item in page.get("Contents", []): print(item["Key"], item["Size"])
# Deletes3.delete_object(Bucket=BUCKET, Key="notes/hello.txt")import { createReadStream } from 'node:fs';import { PutObjectCommand, GetObjectCommand, DeleteObjectCommand, paginateListObjectsV2,} from '@aws-sdk/client-s3';import { Upload } from '@aws-sdk/lib-storage';import { s3 } from './s3.js';
const Bucket = 'my-app-uploads';
// Small objectawait s3.send(new PutObjectCommand({ Bucket, Key: 'notes/hello.txt', Body: 'hello', ContentType: 'text/plain' }));
// Any size file: Upload splits it into 16 MB partsawait new Upload({ client: s3, params: { Bucket, Key: 'videos/video.mp4', Body: createReadStream('video.mp4') }, partSize: 16 * 1024 * 1024, queueSize: 4,}).done();
// Downloadconst obj = await s3.send(new GetObjectCommand({ Bucket, Key: 'notes/hello.txt' }));console.log(await obj.Body.transformToString());
// List (paginated)for await (const page of paginateListObjectsV2({ client: s3 }, { Bucket, Prefix: 'videos/' })) { for (const item of page.Contents ?? []) console.log(item.Key, item.Size);}
// Deleteawait s3.send(new DeleteObjectCommand({ Bucket, Key: 'notes/hello.txt' }));Keep part sizes at 100 MB or less. The SDK defaults (8 MB for boto3, 5 MB for Upload) are fine. See Limits.
Presigned URLs
Section titled “Presigned URLs”Give someone a link that works for a limited time, up to 7 days, without sharing your key. See Presigned URLs and browser uploads for uploads and POST forms.
url = s3.generate_presigned_url( "get_object", Params={"Bucket": "my-app-uploads", "Key": "reports/report.pdf"}, ExpiresIn=3600, # seconds; at most 604800 (7 days))import { GetObjectCommand } from '@aws-sdk/client-s3';import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
const url = await getSignedUrl( s3, new GetObjectCommand({ Bucket: 'my-app-uploads', Key: 'reports/report.pdf' }), { expiresIn: 3600 }, // seconds; at most 604800 (7 days));Other languages
Section titled “Other languages”Go (aws-sdk-go-v2, set UsePathStyle: true), PHP (aws/aws-sdk-php, use_path_style_endpoint), Java, .NET, Ruby and Rust SDKs work the same way: endpoint, region auto, path style, your DH... key.