Используя fastapi, я не могу понять, как отправить несколько файлов в качестве ответа. Например, чтобы отправить один файл, я буду использовать что-то вроде этого
from fastapi import FastAPI, Response
app = FastAPI()
@app.get("/image_from_id/")
async def image_from_id(image_id: int):
# Get image from the database
img = ...
return Response(content=img, media_type="application/png")
Однако я не уверен, как выглядит отправка списка изображений. В идеале я хотел бы сделать что-то вроде этого:
@app.get("/images_from_ids/")
async def image_from_id(image_ids: List[int]):
# Get a list of images from the database
images = ...
return Response(content=images, media_type="multipart/form-data")
Однако это возвращает ошибку
def render(self, content: typing.Any) -> bytes:
if content is None:
return b""
if isinstance(content, bytes):
return content
> return content.encode(self.charset)
E AttributeError: 'list' object has no attribute 'encode'
content
является типомList
, то содержимое цикла:for c in content: c.encode() ...
- person felipsmartins   schedule 11.04.2020img.encode()
на них не работает'bytes' object has no attribute 'encode'
- person Hooked   schedule 11.04.2020