Unable to download though @app.post using StreamingResponse #6538
-
First Check
Commit to Help
Example Codeapp = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/download_test")
async def admin_download_domain_file(request: Request):
import xlsxwriter
from fastapi.responses import StreamingResponse, FileResponse
from io import BytesIO
output = BytesIO()
workbook = xlsxwriter.Workbook(output)
worksheet = workbook.add_worksheet()
worksheet.write(0, 0, "test")
workbook.close()
headers = {"Content-Disposition": "filename=filename.xlsx"}
return StreamingResponse(output, headers=headers)DescriptionI can't download file though @app.post, but if i change it to @app.get, it works fine. Operating SystemLinux Operating System DetailsNo response FastAPI Version0.66.1 Python Version3.9.5 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
|
I tried you code, but work fine. Like this: INFO: 127.0.0.1:50412 - "GET /docs HTTP/1.1" 200 OK
INFO: 127.0.0.1:50412 - "GET /openapi.json HTTP/1.1" 200 OK
INFO: 127.0.0.1:50412 - "POST /download_test HTTP/1.1" 200 OK
INFO: 127.0.0.1:50412 - "POST /download_test HTTP/1.1" 200 OK
INFO: 127.0.0.1:50412 - "POST /download_test HTTP/1.1" 200 OK
INFO: 127.0.0.1:50412 - "POST /download_test HTTP/1.1" 200 OK
INFO: 127.0.0.1:50412 - "POST /download_test HTTP/1.1" 200 OK |
Beta Was this translation helpful? Give feedback.
-
|
@Dustyposa Thanks for your help. According to your words, I finally realize it's the XDM Browser Monitor's problem, it somehow make me jump to GET method. After shutting it down, everything works fine. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, I am getting the same problem at my end. I am returning a FileResponse but the get function gets called instead of rendering the audio/wav response. I dont define nay get function sa i need to return a Filereponse after an input json get posted. I belivee this is related to SwaggerUI perhaps https://github.com/swagger-api/swagger-ui/pull/3441 |
Beta Was this translation helpful? Give feedback.
-
use |
Beta Was this translation helpful? Give feedback.
-
|
Hi, calling curl in shell works fine, its an issue with swagger UI which according to below references has been fixed. Can you please check which swagger UI version is integrated with fastapi current release. I could not get any info on that or how to access the swagger UI code in fastapi https://stackoverflow.com/questions/45224263/swagger-ui-does-not-display-image-png-content-in-post |
Beta Was this translation helpful? Give feedback.
-
|
I'm having the same issue, Is there any way to update the Swagger version in FastApi? |
Beta Was this translation helpful? Give feedback.
-
|
Duplicate: #6284 |
Beta Was this translation helpful? Give feedback.

Duplicate: #6284