Description
Describe 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.