Architecture: where secrets live
The SDK is a browser UI delivered through a public loader + encrypted iframe. Pass an apiKey from the dashboard, register your site under Websites, and keep AWS / blob secrets on a server you control (or use Managed hosting).
| Layer | Role | Credentials |
|---|---|---|
| Browser / SDK | UI, fetch to your APIs | Never embed AWS keys. Public URLs + optional Bearer headers only. |
| Vite demo client | Local demo | Only DEMO_* (see Vite envPrefix). |
| S3 proxy / your API | S3 ListObjects, PutObject, … | AWS_ACCESS_KEY_ID, secret, IAM role, etc. |
Integration checklist
- Create a plan + API key in the dashboard.
- Register every page host under Websites (include
localhostfor local work). - Add
<script src="https://cdn.filestorage.io/loader.min.js"></script>once per page. - Provide a storage backend: your S3 proxy, HTTP API, or Managed storage.
- Call
FileStorageSDK.mount({ el, apiKey, s3 | http })on a container with an explicit height. - Allow CDN + API in CSP (below) and call
unmount()on teardown.
Install (CDN loader — production)
Production embeds load only loader.min.js. There is no public file-storage.min.js or file-storage.css to include.
<div id="fm" style="height: 70vh"></div>
<script src="https://cdn.filestorage.io/loader.min.js"></script>
<script>
FileStorageSDK.mount({
el: '#fm',
apiKey: 'fs_live_…',
s3: {
proxyBaseUrl: 'https://api.example.com/fm',
publicObjectBaseUrl: 'https://cdn.example.com',
},
})
</script>Optional: self-host the loader with curl -fsSL https://cdn.filestorage.io/loader.min.js -o loader.min.js. Bootstrap and encrypted assets still require network access to api.filestorage.io.
Loader & iframe runtime
What happens after mount():
- Loader POSTs to
https://api.filestorage.io/v1/sdk/bootstrapwith your key and page host. - API returns a short-lived session token + one-time content key (only if the key and domain are valid).
- Loader creates an iframe to
https://cdn.filestorage.io/frame.html. - The frame fetches ciphertext from
/v1/sdk/assets/…, decrypts with Web Crypto, injects JS/CSS inside the frame only, then mounts the UI. - Parent ↔ frame talk over
postMessage(resize/errors/picker/auth header refresh).
| CSP directive | Allow |
|---|---|
script-src | https://cdn.filestorage.io |
frame-src | https://cdn.filestorage.io |
connect-src | https://api.filestorage.io + your proxy / HTTP API origin |
SDK repository (local demo)
Use this when developing against the reference S3 proxy or customizing editableOptions. Most product embeds only need the CDN loader above.
yarn # install dependencies
yarn --cwd examples/s3-proxy install
yarn dev:sdk # S3 proxy (:3847) + Vite UI (:3000), reads root .env
yarn build:cdn # loader + encrypted assets (what production ships)Vite demo: DEMO_*
Only DEMO_* keys are exposed to the browser bundle. Pick one store:
S3 via reference proxy (local)
DEMO_STORE=s3
DEMO_S3_PROXY_BASE_URL=http://localhost:3847
DEMO_S3_PUBLIC_BASE_URL=https://your-bucket.s3.us-east-2.amazonaws.comHTTP REST API
DEMO_STORE=http
DEMO_HTTP_API_BASE_URL=https://api.example.comMock (no network)
DEMO_STORE=mock| Variable | Description |
|---|---|
DEMO_STORE | mock | http | s3 |
DEMO_S3_PROXY_BASE_URL | Origin of S3 proxy (POST /list, /upload, …) |
DEMO_S3_PUBLIC_BASE_URL | Public HTTPS origin for object URLs |
DEMO_APP_AWS_UPLOAD_URL | Optional full URL for multipart upload to your app |
DEMO_FM_MAX_CONCURRENT_FETCHES | Max parallel fetches from UI (default 30) |
Reference S3 proxy: server env
Read by examples/s3-proxy only - never shipped to the browser.
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-2
AWS_BUCKET=
REKOGNITION_REGION=us-east-2
S3_ROOT_PREFIX=
S3_PUBLIC_BASE_URL=
PORT=3847editableOptions
File: src/config/editableOptions.ts. Brand mark, demo URL fallbacks, color mode, logos, subscription tier, flat page size, recents limit, virtual trash folder, and more. Restart Vite after changes.
Embedding: FileStorageSDK.mount()
Required: el (selector or element with height) and apiKey. Choose exactly one of s3 or http. Returns { unmount: () => void }.
Optional: widget (full | picker | upload | media), accessMode (full | read-only | upload-only). Auth headers may be functions — the loader asks the parent for fresh headers when the iframe needs them.
S3 proxy store
<div id="fm" style="height: 70vh"></div>
<script src="https://cdn.filestorage.io/loader.min.js"></script>
<script>
FileStorageSDK.mount({
el: '#fm',
apiKey: 'fs_live_…',
s3: {
proxyBaseUrl: 'https://api.example.com/file-manager/s3',
publicObjectBaseUrl: 'https://bucket.s3.us-east-2.amazonaws.com',
headers: () => ({
Authorization: 'Bearer ' + (localStorage.getItem('token') || ''),
}),
connection: {
bucket: 'my-bucket',
region: 'us-east-2',
rootPrefix: 'uploads/app/',
},
},
})
</script>HTTP store
FileStorageSDK.mount({
el: '#fm',
apiKey: 'fs_live_…',
http: {
baseUrl: 'https://api.example.com',
headers: () => ({ Authorization: 'Bearer ' + token }),
endpoints: {
list: '/api/files/list',
upload: '/api/files/upload',
},
},
})Managed storage
On trial / Solo, Pro, and Business, File Storage provisions a tenant prefix on our AWS account (Solo trial includes 15 GB managed storage - or connect BYO S3). You do not run an S3 proxy or hold AWS keys on Managed. Open Dashboard → Managed storage for status and the recommended mount snippet for your account.
// Shape used when Managed HTTP is enabled for your account
// (exact baseUrl is shown in the dashboard).
FileStorageSDK.mount({
el: '#fm',
apiKey: 'fs_live_…',
http: {
baseUrl: 'https://api.filestorage.io/v1/storage',
headers: () => ({
'X-FileStorage-Api-Key': 'fs_live_…',
}),
},
})HTTP backend contract
All routes are POST, relative to baseUrl:
| Route | Body | Returns |
|---|---|---|
POST /api/files/list | { "path": "/" } | { "items": FileEntry[] } |
POST /api/files/folder | { "parentPath", "name" } | - |
POST /api/files/upload | multipart: path, files[] | - |
POST /api/files/rename | { "path", "newName" } | - |
POST /api/files/move | { "path", "destinationFolderPath" } | - |
POST /api/files/remove | { "path" } | - |
POST /api/files/search | { "query" } | items |
POST /api/files/listByType | { "type", "limit?", "cursor?" } | items + nextCursor (optional route) |
Each item in items is a FileEntry:
interface FileEntry {
path: string
name: string
kind: 'file' | 'folder'
mime?: string
size?: number
updatedAt: number // epoch ms
createdAt?: number
url?: string // preview URL
}S3 proxy contract
JSON routes relative to proxyBaseUrl (no /api/files prefix by default):
| Route | Purpose |
|---|---|
POST /list | List folder |
POST /listByType | Paginated type filter |
POST /folder | Create folder |
POST /upload | Multipart upload |
POST /rename · /move · /remove | Mutations |
POST /search | Search |
Optional body field connection: { bucket?, region?, rootPrefix? }. Multipart upload fields: parentPath, files, optional bucket/region/rootPrefix.
Uploads via your app (appAwsUploadUrl)
When set on s3, uploads POST multipart to that full URL; all other operations still use proxyBaseUrl. Use this for auth, validation, virus scanning, or metadata before writing to S3.
Framework guides
Each framework has its own start-to-finish guide: create the project, load the SDK, mount a component, connect storage, then test it with a unit test and a Playwright end-to-end test.
Mobile widgets (iOS & Android)
Ship the full file manager or a UI part (picker, upload, media) inside a WebView. Gallery is public at /widgets; production mounts need Pro+ (same plan as white label).
FileStorageSDK.mountWidget({
el: '#fm',
apiKey: 'fs_live_…',
widget: 'picker', // 'full' | 'picker' | 'upload' | 'media'
s3: { proxyBaseUrl: 'https://api.example.com/fm' },
})Prefer the hosted shell for native apps: https://cdn.filestorage.io/widget.html?apiKey=…&widget=picker&proxyBaseUrl=…
Full iOS, Android, React Native, and Flutter snippets: Mobile widgets guide.
CORS, authentication, and troubleshooting
| Symptom | Fix |
|---|---|
FileStorageSDK is undefined | Confirm loader.min.js returned 200 before mount(). In Next.js / Nuxt load the script in the client layout and wait until window.FileStorageSDK exists. |
| Blank host / zero height | Set an explicit height on the mount element (e.g. 70vh). The iframe fills the host. |
| CSP blocks script or frame | Allow cdn.filestorage.io in script-src and frame-src; allow api.filestorage.io in connect-src. |
| Bootstrap / license error in the host | Check Network for POST /v1/sdk/bootstrap. Fix key, plan, or registered website host. |
DOMAIN_NOT_ALLOWED | Add the page host under Dashboard → Websites (e.g. localhost, app.example.com). |
UNPAID_PLAN / INVALID_API_KEY | Use an active plan and a non-revoked production API key from the dashboard. |
| CORS errors on storage calls | Allow your app origin on the proxy / HTTP API (POST, Content-Type, multipart). |
| 401 / 403 from your proxy | Pass headers: () => ({ Authorization: 'Bearer …' }) on http or s3. |
| 404 on /listByType | Implement the route or restart the example proxy; the SDK falls back to folder walking. |
| Images without previews | Set publicObjectBaseUrl (and optional connection.rootPrefix) so the client can build preview URLs. |
Looking for file-storage.min.js | That file is no longer published. Use loader.min.js only — see Install. |