JavaScript example

JavaScript example for file URL uploads

Use JavaScript from a trusted server, worker, or backend route when your app needs to create a public file URL and return the mapped fields to the client or next job.

JavaScript uploadFormDataserver routeworkerfetch
Runtime

Run the request where the API key is protected.

Server-side JavaScript can enforce account policy and avoid exposing a production bearer key in browser bundles.

01

Backend route

Accept a user upload, call GetFileURL server-side, then return only the fields the UI needs.

02

Worker

Use platform secrets and stream or forward files from an edge function when that matches your architecture.

03

Job runner

Upload generated files from background jobs before passing the returned URL to downstream APIs.

Handling

Keep the response shape explicit in code.

Downstream code should not parse a CDN URL to learn file identity. Use the JSON fields returned by the upload response.

01

url

Send this field to OCR, AI, social, document, CRM, or webhook APIs that fetch files by URL.

02

file_id

Store this field for delete calls and support debugging.

03

expires_at

Use the timestamp to prevent late destination fetches from receiving expired URLs.

Examples

Copy the same upload shape into code or workflow steps

Use the same endpoint from a shell, backend route, worker, or automation code step. Upload the file, set expiry, then map the returned URL.

JavaScript

upload example
const form = new FormData();
form.append("file", file);
form.append("expires_in", "24h");

const res = await fetch("https://api.getfileurl.com/v1/files", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.GETFILEURL_KEY}` },
  body: form,
});

if (!res.ok) throw new Error(`Upload failed: ${res.status}`);
const upload = await res.json();
return { url: upload.url, fileId: upload.file_id };
FAQ

Answers before the workflow breaks

What does the JavaScript example return?

It returns JSON fields including the direct public URL, file ID, content type, and expiry metadata when a retention window is set.

Where should I store the API key?

Store the key in a server environment variable, worker secret, script secret manager, or trusted automation credential store.

What should I do after getting the URL?

Pass `url` to the next API and store `file_id` if the workflow should delete or inspect the file later.

Next pages

Keep building the file URL path

Back to home