Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response data is always string encoded can't send a binary body #107

Open
zootalures opened this issue Jul 2, 2020 · 0 comments
Open

Response data is always string encoded can't send a binary body #107

zootalures opened this issue Jul 2, 2020 · 0 comments

Comments

@zootalures
Copy link
Member

Description

Steps to reproduce the issue:

  1. Create a function that returns a bytes body
import io
import json
import logging
from PIL import Image, ImageDraw
from fdk import response
def handler(ctx, data: io.BytesIO=None):
    img = Image.new('RGB', (60, 30), color='red')
    d = ImageDraw.Draw(img)
    d.text((10, 10), "hello world", fill=(255, 255, 0))
    # write png image to memory 
    output =  io.BytesIO()
    img.save(output, format="PNG")
    # get the bytes of the image 
    imgbytes = output.getvalue()
    return response.Response(
        ctx, response_data=imgbytes,
        headers={"Content-Type": "image/png"}
    )

Describe the results you received:
A string encoded bytes image

(venv) (base) ➜  fdk-python git:(oc/fixBinaryResponses) ✗ curl -v  -X POST http://localhost:8080/invoke/01EC0074S7NG8G00GZJ0000001
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /invoke/01EC0074S7NG8G00GZJ0000001 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 614
< Content-Type: image/png
< Fn-Call-Id: 01EC7NB58GNG8G00GZJ000000D
< Fn-Fdk-Version: fdk-python/dev3
< Date: Thu, 02 Jul 2020 11:42:14 GMT
<
* Connection #0 to host localhost left intact
b’\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00<\x00\x00\x00\x1e\x08\x02\x00\x00\x00\xff\xfa\xea\x18\x00\x00\x00\xa9IDATx\x9c\xed\x96\xd1\n\x80 \x0cE\xb7\xe8\xff\x7f\xd9\x1e”Y\xadt\x89\xde\x12\xeey\x880e\xa7\xeb(5\xc9|,_\x0b\xb4@i\x14\x94FAi\x14\x94FAi\x14k\xe5\xf9~4\xd1\xc0\x1c13\xfdHWz$\xad\xce\xcc\x8ft\xa5\x96\xf4\xce%\xef\x1c\xe4+\xb3\xf2\xaa\\“\x1dW17r\xda\xc3X\xd2v\xd3\x93\x1b\x89\x1b\x17V\xf97\xd1\xbbU*\xd2\xde\x1e\x83\x8e\xe16\x97gb\xed\xe1\x19\xd1\xb2\x1a\xcdB+\xd3.\xbdu\xfbq\x88T\xf2\xdd\xf9T.\xb7\xb5\x158\x97\xaeI\xff\x92)\x7f.\x94FAi\x14\x94FAi\x14SJo\x89l”=T\n?L\x00\x00\x00\x00IEND\xaeB`\x82'%

Describe the results you expected:
A binary image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant