-
First Check
Commit to Help
Example CodeNo Code..
Currently, it is sent to the client as a compressed file(ZipFile).
If it is an image, it will reply with a FileResponseDescriptionIf a client requests multiple images with the keyword “computer”, Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.68 Python Version3.10 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
No, afaik you cannot return multiple files natively without client logic. For example, you could concatenate files together with an agreed upon Seperator and send it as one “file”, but you would have to unconcatenate it on the client side. |
Beta Was this translation helpful? Give feedback.
-
|
Hi Jarro~ Thanks to answer for me.. So.. mean what you say is Zip file is best choice.. isn't it..? |
Beta Was this translation helpful? Give feedback.
-
|
No, the body of your response is either a json body or bytes. In your case, a zip file would be the best response. You could do some hacky solution though, by setting some custom headers containing information you wanted to relay via a json body? Anyway, this is not really a FastAPI issue i guess. |
Beta Was this translation helpful? Give feedback.
-
|
You need client side logic, StreamingResponse maybe can help you, when I return documents like return StreamingResponse(
buffer, # BytesIO Object to return
media_type="text/csv",
headers={
"Content-Disposition": "attachment;filename=contacts.csv", # ref: https://developer.mozilla.org/es/docs/Web/HTTP/Headers/Content-Disposition
"Content-Type": "text/csv"
}
) |
Beta Was this translation helpful? Give feedback.
-
|
Thank you answer.. |
Beta Was this translation helpful? Give feedback.
-
Thank you answer~ |
Beta Was this translation helpful? Give feedback.
No, afaik you cannot return multiple files natively without client logic. For example, you could concatenate files together with an agreed upon Seperator and send it as one “file”, but you would have to unconcatenate it on the client side.