@storecraft/storage-s3-compatible
v1.0.6
Published
Official S3-Compatible Storage adapter for storecraft
Downloads
109
Maintainers
Readme
Storecraft S3 compatible storage
fetch
ready support for an S3
like storage:
Amazon S3
Cloudflare R2
DigitalOcean Spaces
minIO
servers
Features:
- Works in any
js
runtime and platform that supportsfetch
- Supports streaming
Get
/Put
/Delete
- Supports
presigned
Get
/Put
requests to offload to client
npm i @storecraft/storage-s3-compatible
usage
import { R2, S3, DigitalOceanSpaces, S3CompatibleStorage } from '@storecraft/storage-s3-compatible'
const storage = new R2({
accessKeyId: process.env.R2_ACCESS_KEY_ID,
account_id: process.env.R2_ACCOUNT_ID,
bucket: process.env.R2_BUCKET,
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY
});
// write
await storage.putBlob(
'folder1/tomer.txt',
new Blob(['this is some text from tomer :)'])
);
// read
const { value } = await storage.getBlob('folder1/tomer.txt');
const url = await storage.getSigned('folder1/tomer.txt');
console.log('presign GET url ', url);
In Storecraft App
import { App } from '@storecraft/core';
import { MongoDB, migrateToLatest } from '@storecraft/database-mongodb';
import { NodePlatform } from '@storecraft/core/platform/node';
import { R2 } from '@storecraft/storage-s3-compatible'
const app = new App(
{
storage_rewrite_urls: undefined,
general_store_name: 'Wush Wush Games',
general_store_description: 'We sell cool retro video games',
general_store_website: 'https://wush.games',
auth_secret_access_token: process.env.auth_secret_access_token,
auth_secret_refresh_token: process.env.auth_secret_refresh_token
auth_admins_emails: ['[email protected]']
}
)
.withPlatform(new NodePlatform())
.withDatabase(new MongoDB())
.withStorage(
new R2(
process.env.R2_BUCKET,
process.env.R2_ACCOUNT_ID,
process.env.R2_ACCESS_KEY_ID,
process.env.R2_SECRET_ACCESS_KEY
)
);
await app.init();
await migrateToLatest(app.db, false);
Author: Tomer Shalev ([email protected])