Python example

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
Python uploadrequestsscriptsdata pipelineOCR
Example
Language
Python
Input
invoice.pdf
Output
url and file_id
Short answer

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
Handoff

One request in, a URL and JSON out

Request
import os
import requests
Response
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"])
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

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"])
FAQ

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.