Conversation
| image_bytes = buffer.getvalue() | ||
|
|
||
| # Create and return response with appropriate headers | ||
| return Response( | ||
| to_js(image_bytes).buffer, | ||
| headers={ | ||
| "Content-Type": content_type, | ||
| "Cache-Control": "public, max-age=3600", | ||
| }, | ||
| ) |
There was a problem hiding this comment.
One copy instead of two:
| image_bytes = buffer.getvalue() | |
| # Create and return response with appropriate headers | |
| return Response( | |
| to_js(image_bytes).buffer, | |
| headers={ | |
| "Content-Type": content_type, | |
| "Cache-Control": "public, max-age=3600", | |
| }, | |
| ) | |
| image_bytes = create_proxy(buffer.getvalue()) | |
| jsbuffer = image_bytes.getBuffer() | |
| try: | |
| # Create and return response with appropriate headers | |
| return Response( | |
| jsbuffer.data, | |
| headers={ | |
| "Content-Type": content_type, | |
| "Cache-Control": "public, max-age=3600", | |
| }, | |
| ) | |
| finally: | |
| image_bytes.destroy() | |
| jsbuffer.release() |
There was a problem hiding this comment.
The problem is presumably that the Response constructor is somehow messing up array buffer views. We should figure out where that is messed up and fix it.
There was a problem hiding this comment.
cc @ryanking13 this might be a good issue for you to investigate.
There was a problem hiding this comment.
Yeah, it looks like it doesn't take Uint8Array type as a Response. The error log that I get in the console is
TypeError: Unsupported type in Response: Uint8Array
Raw ArrayBuffer seems to work fine, but it doesn't seem to handle ArrayBufferView.
I was able to make it work with the following workaround but it involves copying in slice anyways.
image_bytes = create_proxy(buffer.getvalue())
jsbuffer = image_bytes.getBuffer()
# ...
return Response(
jsbuffer.data.slice(0, jsbuffer.data.byteLength).buffer,
)There was a problem hiding this comment.
Perhaps we need a fix to JavaScript Response:
const a = new TextEncoder().encode("hello there!!")
const b = a.subarray(3)
const r = new Response(b)
console.log(await r.text()); // 'lo there!!'There was a problem hiding this comment.
Okay nevermind that clearly works.
08c0160 to
eb78296
Compare
1188ea0 to
2a53cd0
Compare
d81e4e9 to
873157c
Compare
db3ed55 to
935df31
Compare
hoodmane
left a comment
There was a problem hiding this comment.
It'd be good to improve this when we figure out what's going on with the Reponse constructor but this is good for now.
| image_bytes = buffer.getvalue() | ||
|
|
||
| # Create and return response with appropriate headers | ||
| return Response( | ||
| to_js(image_bytes).buffer, | ||
| headers={ | ||
| "Content-Type": content_type, | ||
| "Cache-Control": "public, max-age=3600", | ||
| }, | ||
| ) |
There was a problem hiding this comment.
Okay nevermind that clearly works.
6498ba2 to
7ac8ba0
Compare
for more information, see https://pre-commit.ci
|
Tracking via EW-9793 |

Deployed URL: https://python-image-gen.runtime-playground.workers.dev
Mostly generated using GenAI.
CC @ryanking13