Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

file-storage

Key/value storage interfaces for server-side File objects. file-storage gives Remix apps one consistent API across local disk and memory backends.

Features

  • Simple API - Intuitive key/value API (like Web Storage, but for Files instead of strings)
  • Multiple Backends - Built-in filesystem and memory backends
  • Streaming Support - Stream file content to and from storage
  • Metadata Preservation - Preserves all File metadata including file.name, file.type, and file.lastModified

Installation

npm i remix

Usage

File System

import { createFsFileStorage } from 'remix/file-storage/fs'

let storage = createFsFileStorage('./user/files')

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)

Related Packages

  • file-storage-s3 - S3 backend for file-storage
  • form-data-parser - Pairs well with this library for storing FileUpload objects received in multipart/form-data requests
  • lazy-file - The streaming File implementation used internally to stream files from storage

License

See LICENSE