Why use a hosted file service from Django
Your Django app can keep files on its own disk, or in a bucket it has to configure, secure and resize for. With Fileboy the app sends the file once, gets an ID back and keeps only that ID. Images are resized by changing a URL, so there is no image processing in your app, and the same ID works from any language.
1. Install the package
pip install fileboyYou need a public key. Create a free app and copy it from the Keys page. Keep keys out of your code: read them from credentials or the environment.
2. Configure it once
import os
import fileboy
fileboy.configure(
public_key=os.environ["FILEBOY_PUBLIC_KEY"],
private_key=os.environ.get("FILEBOY_PRIVATE_KEY"), # optional
)3. Upload and keep the ID
Pass the uploaded file through. The call returns the file's details, and the id is the only thing to store.
import fileboy
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect
@login_required
def upload_avatar(request):
upload = request.FILES["avatar"]
try:
file = fileboy.client().upload_file(
upload.file,
name=upload.name,
mime=upload.content_type,
)
except fileboy.FileboyError as error:
return redirect(f"/profile/?error={error.code}")
request.user.profile.avatar_fileboy_id = file.id
request.user.profile.save(update_fields=["avatar_fileboy_id"])
return redirect("/profile/")class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
avatar_fileboy_id = models.CharField(max_length=36, blank=True)4. Show the image at the size you need
Build the URL from the stored ID. Asking for the size you display keeps pages light, and the original is never changed.
import fileboy
from django import template
register = template.Library()
@register.simple_tag
def avatar_url(profile, size=96):
if not profile.avatar_fileboy_id:
return ""
return fileboy.client().build_image_url(
profile.avatar_fileboy_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. Uploads are what your key authorises.
Checked against the current libraries in November 2026. Found something that no longer works? Tell us.