[QUESTION] variable (file) field
See original GitHub issueFirst check
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
Description
I’m looking for what’s the best way to have a function accept a multipart/form-data
file in different configurations:
a) a specific form field like photo or movie? The file has to be uploaded as photo
field then.
I need to support a request like this:
requests.post(
url='http://localhost/test',
files=[{'photo': ('foo.png', open('foo.png', 'rb'), 'image/png')}],
)
b) be able to name the file to use, e.g. photo="attach://somefield"
.
The request would look like:
requests.post(
url='http://localhost/test',
params={'photo': 'attach://random_key_banana'},
files=[{'random_key_banana': ('foo.png', open('foo.png', 'rb'), 'image/png')}],
)
In both cases I’d like to end up with a variable photo
containing the uploaded file (how doesn’t matter, I’m happy with anything like a tmp file path, a python file-like, or even a raw bytearray)
I feel like I could handle a) with
photo: UploadFile = File(...)
But how can I receive files in arbitrary fields like need for b)? The only thing I could think of is
**kwargs: Dict[str, UploadFile] = List([File(...)])
but obviously that doesn’t work.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Setting variables (and doing other things) with questions
Within a fields question, there are many possible datatype values that you can use. These affect what the user sees and how the...
Read more >returning field names as variables from a file - Forums - IBM
Using RPG, how can I return the field names from a physical file to be used as variables (in particular, in an SQL...
Read more >Custom Field Creation - Qualtrics
Creating custom fields allows you to add new variables to responses after they've already been recorded. You can categorize based on items like...
Read more >In Django, how to create file field database variable in a query?
you need to understand Django ORM first : When you do Information.objects.earliest("id") : you will get the query executed in the database.
Read more >Using Variables to Select Field / Insert File - Claris Community
migration.user (Employee) asked a question. May 23, 2012 at 7:46 PM. Using Variables to Select Field / Insert File. Title. Using Variables to...
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
You can start by reading fastapi code since I guess that’s a bit low level, but you can start with https://fastapi.tiangolo.com/advanced/using-request-directly/
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.