Skip to content

Send Image data in the queue #1450

Answered by Dronakurl
Dronakurl asked this question in Q&A
May 16, 2024 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

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

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()


Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@Dronakurl
Comment options

@sheldygg
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Dronakurl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants