-
Hi, I am new to faststream. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Sure, you can send raw bytes with FastStream the following way @broker.subscriber(...)
async def handler(file: bytes):
....
await broker.publish(b"file_content", ....) But you should be accurate with your files size. Probably, you should take a look at NATS Object Storage feature or upload your files to S3 and subscribe on its events |
Beta Was this translation helpful? Give feedback.
-
Apparently, transferring bytes works in faststream, but not with the fastapi plugin. from pathlib import Path
from fastapi import Depends, FastAPI
from faststream.kafka.fastapi import KafkaRouter, Logger
from pydantic import BaseModel
router = KafkaRouter("localhost:9092")
class Incoming(BaseModel):
m: dict
def call():
return True
@router.subscriber("test")
@router.publisher("response")
async def hello(m: Incoming, logger: Logger, d=Depends(call)):
logger.info(m)
# >> This works
# return "hUHU"
# >> This doesn't -> decoding error
return Path("tt.jpg").read_bytes()
@router.after_startup
async def test(app: FastAPI):
await router.broker.publish(Incoming(m=dict()), "test")
@router.get("/")
async def hello_http():
return "Hello, HTTP!"
app = FastAPI(lifespan=router.lifespan_context)
app.include_router(router) |
Beta Was this translation helpful? Give feedback.
Apparently, transferring bytes works in faststream, but not with the fastapi plugin.
When adapting the example on the webpage to bytes output, it raises the
UnicodeDecodeError