[QUESTION] Customizing UploadFile
See original GitHub issueDescription
I found issue with Starlette’s UploadFile
where it actually always buffers file to RAM fully and never switches to disk.
To overcome this until new version lands, I want to use my own version of UploadFile
. This is what I tried:
import logging
from fastapi import FastAPI, File, UploadFile
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
app = FastAPI()
class FixedUploadFile(UploadFile):
def __init__(self, *args, **kwargs):
logger.info("FixedUploadFile is initializing...")
super().__init__(self, *args, **kwargs)
self.file.rollover()
@app.post("/uploadfile/")
async def create_upload_file(file: FixedUploadFile = File(...)):
logger.info("Upload file handler")
return {"filename": file.filename}
Running this I see that “FixedUploadFile is initializing…” is not called. How can I supply a custom class for UploadFile
? (Either FastAPI’s or Starlette’s)
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
File Upload Custom Question - RSVPify Help Center
To set up your file upload custom question you need to: Step 1: Navigate to Form Builder and locate the 'Custom Question' form...
Read more >File Upload Question - Qualtrics
Import Responses · CSV/TSV Upload Issues · Retake Survey Link · Combining Responses · Response Editing; Creating New Fields. Custom Field Creation ...
Read more >Create File Upload Questions - WebAssign
Create File Upload Questions · Click Questions > Create. · In Name, type a name for the question. · In Mode, select File-Upload....
Read more >How to Add a File Upload Question in Google Forms and Why
For documents, images, and videos, have a respondent upload a file in Google Forms. Here's how to add and customize that question type....
Read more >Attaching a File to a Custom Question - Smartwaiver Support
5. Within your new custom section, click and drag the Upload Files question option (from the left sidebar) into your custom question section....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah… gross… Thanks though. Here is another one. We can start code-ugly competition 😃
@tiangolo this ticket was about customizing
UploadFile
in FastAPI, but the use case was a bug in then currentUploadFile
implementation. The bug was fixed at https://github.com/encode/starlette/issues/579 long time ago, but this ticket was left open since it was about customizingUploadFile
which is still not possible without monkey patching.I think it’s indeed resolved for now, because the only reason to customize was to work around a Starlette bug, hence the original use case became irrelevant and with it the whole reason to customize 😃