I currently have a Fastapi App Engine app. It handles file uploads from a form, processes the file, adds a record of it to a DB, and saves the file in a Google Cloud storage bucket. However, the app engine limits the file upload size of a POST request to 35mb. I can test the app locally and it works perfectly, but the GCloud GFE causes the endpoint to return a status code of 413 for any large files. Below you can see the code I'm using to handle file uploads.
@router.post('/upload')
def upload(name: str = Form(...), file: UploadFile = File(...), db=Depends(get_session)):
"""
Uploads a file to the server
"""
if not file.content_type.startswith('video/'):
error = "File must be a video"
return RedirectResponse(url='/files?error_message=' + error, status_code=302)
create_db_record(db, name, file)
storage_client = storage.Client.from_service_account_json('service_account.json')
bucket = storage_client.get_bucket('myapp.appspot.com')
blob = bucket.blob(file.filename)
blob.upload_from_file(file.file)
return RedirectResponse(url='/')
If I were to directly upload the file to the bucket, i wouldn't be able to process it first, but sending it through the upload form isn't an option if it is going to be over 35mb. How do I allow this Fastapi post request to accept larger files to be able to upload to the bucket? All of the documentation I have found doesn't show how to handle it from the fastapi/django side.