Python example for file URL uploads
A script, worker, scheduled job, or data pipeline creates the file. Upload it once and pass the returned HTTPS URL to the next service.
- Reviewed by
- GetFileURL technical team
- Updated
- Language
- Python
- Input
- invoice.pdf
- Output
- url and file_id
What this page answers
It returns JSON fields including the direct public URL, file ID, content type, and expiry metadata when a retention window is set.
- Reviewed by
- GetFileURL technical team
- Last updated
One request in, a URL and JSON out
import os
import requestswith 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={"visibility": "public"},
timeout=30,
)
response.raise_for_status()
upload = response.json()
print(upload["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
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={"visibility": "public"},
timeout=30,
)
response.raise_for_status()
upload = response.json()
print(upload["url"])Common questions
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.