Accessing attachment thumbnail URL from record value

I’m building a custom app and need to show an attachment’s thumbnail image as part of an info card.

When I enter <div>{record.getCellValue("Attachment field")}</div> to view the cell values, I get the following error:

Error: Objects are not valid as a React child (found: object with keys {linkedRecordId, value}). If you meant to render a collection of children, use an array instead.

I’ve tried adding record.getCellValue("Attachment field").fields.url but it comes up as undefined.

I’ve also tried { => {value.url})} to try access the object’s properties but map is not a function of record.

How can I access the thumbnail’s URL?

Try something like:

record.getCellValue("Attachment field")?.map(x => {
   var url= x.url
   return (<img src={url} />)
1 Like

Hi Michael,

Adding on to Kamille’s solution: the cell value formats for all the different field types are documented here: Airtable Blocks SDK

The cell value for attachment fields is an array of attachment objects (even if there’s only one attachment), so you’ll need to get the url(s) from those individual attachment objects.

1 Like

Right on, thanks to @Kamille_Parks and @Emma_Yeap I was able to piece it together:

{record.getCellValue("Lookup attachment field")?.map(x => {
    var url= x.value.thumbnails?.large?.url
    return (<img src={url} />)

The extra value property is what allows this to work with a lookup field pointing to an attachment in another table if that is helpful to anyone.

To clarify for others only add .value if you’re pulling from a Lookup field. This question was asked regarding Attachment fields. Actual attachment fields do not return a value property within the object returned by .getCellValue().

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.