Skip to content

remix/file-storage/fs · Function

View Source

createFsFileStorage

Summary

Creates a FileStorage that is backed by a filesystem directory using node:fs.

Use a directory dedicated to this backend and managed by the application, with consistent filesystem user, groups, and directory inheritance rules across restarts and deployments. Existing storage directories can be reused; storing a file under an existing key replaces that entry.

Writes stage complete content and metadata before replacing their existing files with two atomic renames. Upload failures during staging preserve the previous entry. If the content rename succeeds but the metadata rename fails, or the process stops between them, new content remains with old metadata (or no metadata for a new key). A rejected write may have changed the content. The storage format remains compatible with older versions.

Requires a filesystem that supports atomic rename and permission to create, rename, and remove files in the storage subdirectories. Existing POSIX read/write/execute mode bits are preserved; owner, group, and ACLs follow the filesystem's rules for newly created files. Custom per-file ownership and ACL changes are not preserved. Callers must coordinate overlapping operations, including consumption of returned lazy files. Temporary cleanup is best-effort, and power-loss durability is not guaranteed.

Keys are hashed to determine paths on disk, so they may contain characters that are not valid in filenames. A file's name and other metadata do not affect its storage path; files with the same name can be stored under different keys.

Signature

function createFsFileStorage(directory: string): FileStorage<LazyFile>

Parameters

directory

The directory where files are stored

Returns

A new FileStorage backed by a filesystem directory