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 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.
Document processing
Upload invoices, reports, and contracts before sending the URL to extraction or OCR APIs.
Data exports
Create a CSV or report, upload it, then pass the public URL to a workflow, CRM, or notification step.
AI workflows
Host generated images or files long enough for moderation, evaluation, or publishing jobs.
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.
Timeouts
Set request timeouts so a stuck upload does not block the whole worker.
Error handling
Use structured error codes to decide whether the job should retry, delay, or fail fast.
Cleanup
Store file IDs so scheduled cleanup can delete files after downstream processing.
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 exampleimport 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"])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.