@edgefirst-dev/r2-file-storage

1.0.0 • Public • Published

r2-file-storage

An implementation of @mjackson/file-storage that uses R2 as the storage backend.

Features

  • Simple, intuitive key/value API (like Web Storage, but for Files instead of strings)
  • A generic FileStorage class that works for various Cloudflare R2.
  • Preserves all File metadata including file.name, file.type, and file.lastModified

Installation

Install from npm or GitHub Package Registry with;

bun add @edgefirst/r2-file-storage

Usage

import { R2FileStorage } from "@edgefirst/r2-file-storage";

let storage = new R2FileStorage(r2); // Get r2 from your Cloudflare bindings

let file = new File(["hello world"], "hello.txt", { type: "text/plain" });
let key = "hello-key";

// Put the file in storage.
await storage.set(key, file);

// Then, sometime later...
let fileFromStorage = await storage.get(key);
// All of the original file's metadata is intact
fileFromStorage.name; // 'hello.txt'
fileFromStorage.type; // 'text/plain'

// To remove from storage
await storage.remove(key);

License

See LICENSE

Author

Readme

Keywords

none

Package Sidebar

Install

npm i @edgefirst-dev/r2-file-storage

Weekly Downloads

75

Version

1.0.0

License

MIT

Unpacked Size

7.19 kB

Total Files

9

Last publish

Collaborators

  • sergiodxa