[QUESTION] error uploading a file with a post request
See original GitHub issueDescription
How do I upload a file with a post request? I have done what is described here - https://fastapi.tiangolo.com/tutorial/request-files/ - so the following code is in my main.py file
from fastapi import FastAPI, Request, File, UploadFile
app = FastAPI
@app.post('/uploaddata/')
async def create_upload_file(file: UploadFile = File(...)):
return {"filename": file.filename}
and on the client side i have a simple form like this:
<form method="post" action="/uploaddata/" enctype="multipart/form-data">
<button class="btn btn-outline-secondary" type="submit">upload</button>
<input type="file" id="file_upload">
</form>
I get the error: {“detail”:“There was an error parsing the body”}, just like issue #201 https://github.com/tiangolo/fastapi/issues/201 In that case the problem seemed to be that python-multipart wasn’t installed. I have installed it, but I still get the error. Is there something obviously wrong? If not, how can I get hold of more information that just this reply: {“detail”:“There was an error parsing the body”}?
thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
File Upload in Angular giving error when posting POST request
You are sending only file name but not actual file blob. Try to do below changes,. component.ts : uploadFile() { this.currentFile = this....
Read more >Error 500 when uploading a file via API - Canvas Community
I figured this out finally. It appears that posting to inscloudgate requires that you include the "filename" as part of the form data...
Read more >File Upload Question - Qualtrics
... Building a Consent Form · Displaying Messages Based on Scoring · Screen-Out Management · Survey Tips & Tricks · Starting a Survey...
Read more >Question: How to upload a file using HTTP POST Form-Data?
I want to upload a file using HTTP POST where username and password are to be filled using form-data.
Read more >File Upload Question - SurveyMonkey Help
File Upload questions support the following file types: PDF; DOC, DOCX; PNG; JPG, JPEG; GIF ... Customize the error message that appears when...
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 are missing the
name
attribute on the HTML form, it must be the same as the parameter name (in your casefile
). So:This question links to this issue.