Python example

Python example for file URL uploads

Use Python when a script, worker, scheduled job, or data pipeline creates a file that another service needs to fetch by public HTTPS URL.

Python uploadrequestsscriptsdata pipelineOCR
Use cases

Python fits batch jobs that create files before the next API step.

Scripts and data jobs often generate PDFs, CSVs, images, or exports that need a temporary public URL for another system.

01

Document processing

Upload invoices, reports, and contracts before sending the URL to extraction or OCR APIs.

02

Data exports

Create a CSV or report, upload it, then pass the public URL to a workflow, CRM, or notification step.

03

AI workflows

Host generated images or files long enough for moderation, evaluation, or publishing jobs.

Production notes

Set timeouts and treat failed uploads as job failures.

A file URL handoff should be observable. Log response codes and request context without logging the API key.

01

Timeouts

Set request timeouts so a stuck upload does not block the whole worker.

02

Error handling

Use structured error codes to decide whether the job should retry, delay, or fail fast.

03

Cleanup

Store file IDs so scheduled cleanup can delete files after downstream processing.

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.

Python

upload example
import os
import requests

with open("invoice.pdf", "rb") as file:
    response = requests.post(
        "https://api.getfileurl.com/v1/files",
        headers={"Authorization": f"Bearer {os.environ['GETFILEURL_KEY']}"},
        files={"file": file},
        data={"expires_in": "24h"},
        timeout=30,
    )

response.raise_for_status()
upload = response.json()
print(upload["url"])
FAQ

Answers before the workflow breaks

What does the Python 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