Published
What you are building
A Flask view reads the file from request.files and hands its stream to Fileboy. The call returns the file's details, and the id is what you store.
1. Install and set your keys
pip install fileboy flaskimport os
import fileboy
client = fileboy.Client(
public_key=os.environ["FILEBOY_PUBLIC_KEY"],
private_key=os.environ.get("FILEBOY_PRIVATE_KEY"), # optional
)You need a public key. Create a free app and copy it from the Keys page. Keep keys in environment variables, and never put a private key in code that reaches the browser. An upload needs only the public key; add the private key only if your app uses signed requests.
2. Upload the file
import fileboy
from flask import Flask, jsonify, request
from fileboy_client import client
app = Flask(__name__)
app.config["MAX_CONTENT_LENGTH"] = 20 * 1024 * 1024 # refuse bodies over 20 MB with a 413
@app.post("/avatar")
def upload_avatar():
avatar = request.files.get("avatar")
if avatar is None or not avatar.filename:
return jsonify(error="Choose a file"), 400
try:
file = client.upload_file(avatar.stream, name=avatar.filename, mime=avatar.mimetype)
except fileboy.FileboyError as error:
return jsonify(error=str(error)), 502
# save file.id against the user here
return jsonify(id=file.id)curl -F "avatar=@./photo.jpg" http://localhost:5000/avatarStore the id the upload returns and nothing else: it is the only thing you need to show the file again, at any size.
3. Show it at the size you need
from fileboy_client import client
def avatar_url(file_id, size=96):
return client.build_image_url(
file_id,
transforms=[
{"type": "resize", "width": size * 2, "height": size * 2, "fit": "cover"},
{"type": "format", "format": "webp"},
],
)Reading a file or image needs no key, so these URLs work in <img> tags, emails and anywhere else, unless the app requires signed URLs.
Checked against the current libraries in November 2026. Found something that no longer works? Tell us.