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 |
| 2 | const db = await PrefsDB.getkey("my-app", words); |
| 3 | |
| 4 | // upload the file picked in <input type="file"> |
| 5 | const res = await db.putObject(input.files[0]); |
| 6 | |
| 7 | // stored encrypted; the link works right away |
| 8 | img.src = res.shareViewUrl; |
| 9 | |
| 10 | // keep the id to fetch or delete it later |
| 11 | const id = res.file; |
| 1 | const db = await PrefsDB.getkey("my-app", words); |
| 2 | |
| 3 | // scope uploads like keys: domain, subdomain, |
| 4 | // project and list nest into folders |
| 5 | await db.domain("uploads") |
| 6 | .project("avatars") |
| 7 | .putObject(avatar); |
| 8 | |
| 9 | // same file name + same scope: overwritten in place |
| 10 | await db.domain("uploads") |
| 11 | .project("avatars") |
| 12 | .putObject(newAvatar); |
| 13 |
| 1 | const db = await PrefsDB.getkey("my-app", words); |
| 2 | |
| 3 | // no <input>? build a File from your own data |
| 4 | const report = new File( |
| 5 | [JSON.stringify(stats)], "report.json" |
| 6 | ); |
| 7 | const res = await db.putObject(report); |
| 8 | |
| 9 | if (!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 |
| 2 | curl -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=..." } |