Binary data in binary format is not binary?
See original GitHub issueDescribe the Bug
I’m trying to send a cloudevent with datacontenttype
of image/jpeg
and the actual payload being the bytes of the image. It seems like the current code in asData
will always base-64 the content when fetching data. (Possibly twice, if I read the code at line 12 of http/index.js
correctly – once for event.data
, and once for asData
.)
Steps to Reproduce
I’d like the following code to work, but it appears that ArrayBuffer
and Blob
are not supported types for data:
fetch(mediaUrl).then(async (resp) => {
let newEvent = event.cloneWith({
source: sourceUrl,
type: responseEventType,
datacontenttype: resp.headers.get("Content-Type")
})
// I want this. This definitely does not work, and an empty object gets encoded.
newEvent.data = await resp.arrayBuffer(); // or .blob()
const response = HTTP.binary(newEvent);
res.status(200).set(response.headers).send(response.body);
});
If I try to convert the arrayBuffer to a Uint32Array (newEvent.data = new Uint32Array(await resp.arrayBuffer());
), I get the following exception:
TypeError: Cannot assign to read only property ‘data_base64’ of object ‘[object Object]’
Expected Behavior I’d like the above code to work, or to be able to find an example of sending a binary file (i.e. an image or a proto or something) as an HTTP CloudEvent.
Additional context I am terrible at Javascript, so feel free to point out I’m holding it wrong.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I have a demo that I’m wrapping up, but I’ll try figuring out how to patch this in on a branch probably tomorrow morning once I’ve got the demo recorded. 😁
I think you should be able to do that with the changes in #344, but you could not convert it to a
Message
. You would need to do something like this.