Ingesting a binary PNG response

Hi Coda Community!

I’m building a Pack and it returns an image response. I am wondering if it’s possible to get Coda to digest the response which is a binary PNG literally.

I want it to persist in the doc, and having some difficulty after a couple days with it. I’m using this:

let imageBlob = await response.body; // Getting the binary PNG data
let imageUrlBlob = await context.temporaryBlobStorage.storeBlob(imageBlob, "image/png");
return imageUrlBlob;

Then I load my response into a Table with Image URL format type, but it seems to expire in the Coda Doc after an hour or so. I’d like it to persist.

Thank you!

1 Like

Hey Michael! I think the trick of ingesting permanently is using the column type: File

Please have a try with that :slight_smile:

Hi Rickard,

Thanks very much for your reply! :slightly_smiling_face: I just tried to use the following column types, including:File:

  • File: My button says it modified the row, but I don’t see the image or anything in it
  • Image - Same as above
  • Image URL - Accepted and rendered my image from the temporaryBlobStorage.storeBlob

The only one that seems to render my image after I click my button is “Image URL”. Is there an another approach to try to get Coda to host the image permanently?

My image comes from my own rendering endpoint, so I highly prefer to just pass the result back to my Coda Pack, and get Coda to host the image permanently.

I should mention I’m using this in my addFormula:

  resultType: coda.ValueType.String,
  codaType: coda.ValueHintType.ImageAttachment,
  isAction: true,
1 Like

I think that all looks good, and my PDF pack code is pretty identical, I’m not sure why it doesn’t show up in the File cell

See my example here

Do you have isBinaryResponse: true, as well? I think you do, if the temporary image worked

How do you create the response body on the endpoint?

Edit:
Oh I think I found it, I forgot you need to call ToText() before giving it to File for some reason, so intuitive :sweat_smile:

thisRow.ModifyRows([Picture File], PDF::PicturePDFs(PDFs).ToText())
1 Like

Thanks for the example, I appreciate your advice.

I tried quite a while to get it to work like yours with Files and Attachments, although I struggled with schemas to try to push my PNG as an Attachment to get it fully hosted and fully persistent on Coda’s end. I was hoping there was a command like:

context.makeAttachment(my_image_from_url_OR_binary_png)

As I’m new to Coda :sweat_smile: I decided to restructure my systems for a different approach. Now I will host the renders, and provide a unique image url for the Pack. Although I have to expire them at a point and clear them out to keep it lean. Previously with my other non-hosting version, I was just returning the literal PNG directly to the Coda Pack:

res.setHeader('Content-Type', 'image/png');
res.send(resultingImage);
1 Like

I just came back to try this again - and got it to work this time! :sweat_smile:

It now attaches my image made into the Doc using my hosted url. So it looks like it’s partially working for that step!

I had to write it like this from a button action (I was missing that). Thanks very much for your help.

// From a button
ModifyRows(thisRow, thisRow.[Final Image Attached], thisRow.CurrentImageUrl.toText())
1 Like