PRODUCTS

File Storage

No need for a separate file storage system. PrefsDB offers file storage and data in one place. Use putObject / getObject methods store and retrieve files.

  • No S3 buckets to configure
  • No cloud storage fees
  • All assets are encrypted when at rest
  • All uploaded assets get a unique embeddable URL ready for immediate use in your static pages.


1// mint a key from a phrase only your user knows
2const db = await PrefsDB.getkey("my-app", words);
3 
4// upload the file picked in <input type="file">
5const res = await db.putObject(input.files[0]);
6 
7// stored encrypted; the link works right away
8img.src = res.shareViewUrl;
9 
10// keep the id to fetch or delete it later
11const id = res.file;
1const db = await PrefsDB.getkey("my-app", words);
2 
3// scope uploads like keys: domain, subdomain,
4// project and list nest into folders
5await db.domain("uploads")
6 .project("avatars")
7 .putObject(avatar);
8 
9// same file name + same scope: overwritten in place
10await db.domain("uploads")
11 .project("avatars")
12 .putObject(newAvatar);
13 
1const db = await PrefsDB.getkey("my-app", words);
2 
3// no <input>? build a File from your own data
4const report = new File(
5 [JSON.stringify(stats)], "report.json"
6);
7const res = await db.putObject(report);
8 
9if (!res.success) {
10 // e.g. "File too large" (12 MB max per file)
11 console.error(res.message);
12} else {
13 // this upload counts toward your bucket's cap
14 console.log(res.storage_used, "of", res.storage_max);
15}
1# dashboard-issued key, a plain bearer token
2curl -s https://prefsdb.com/api/v1/putobject/ \
3 -H "X-Authorization: Token $PREFSDB_SERVER_KEY" \
4 -F "file=@./photo.jpg" \
5 -F "project=avatars"
6 
7# => { "success": true, "file": "...",
8# "shareUrl": "https://prefsdb.com/dl/?t=..." }