Skip to content

How To #8

How to pass request files to your endpoints

To receive files sent as form data you can declare an argument with default value of File(...).

from fastapi import File

def post(file_contents: bytes = File(...)):

  return {}

We can use Brev's built in file upload function to save the file and return a link to it!

from fastapi import File
import file_storage

def post(file_contents: bytes = File(...)):

  link = file_storage.upload(file_contents)

  return {"file_url": link}