Better Upload

Helpers

A collection of helper functions and utilities for your project.

S3 Clients

better-upload has some built-in clients for popular S3-compatible storage services, like Cloudflare R2. Suggest a new client by opening an issue.

Cloudflare R2

import { r2 } from 'better-upload/server/helpers';
 
const client = r2({
  accountId: 'your-account-id',
  accessKeyId: 'your-access-key-id',
  secretAccessKey: 'your-secret-access-key',
});

This returns an instance of an S3 Client from the AWS SDK, just like new S3Client(), but already configured for Cloudflare R2.

Jurisdiction

If your created your R2 bucket using a jurisdiction, you can specify it here.

import { r2 } from 'better-upload/server/helpers';
 
const client = r2({
  accountId: 'your-account-id',
  accessKeyId: 'your-access-key-id',
  secretAccessKey: 'your-secret-access-key',
  jurisdiction: 'eu', 
});

Minio

import { minio } from 'better-upload/server/helpers';
 
const client = minio({
  region: 'your-minio-region',
  endpoint: 'https://minio.example.com'
  accessKeyId: 'your-access-key-id',
  secretAccessKey: 'your-secret-access-key',
});

Bucket Objects

Move object (rename)

Moves an object from one location to another, within the same bucket. Also known as renaming.

import { moveObject } from 'better-upload/server/helpers';
 
await moveObject({
  client: r2(),
  bucketName: 'your-bucket-name',
  objectKey: 'example.jpg',
  destinationKey: 'images/example.jpg',
});

This copies the object to the new location and then deletes the original object. It can be slow.

On this page