Trying to use Airtable as CMS - resources.GetRemote Airtable Image link problem

After the answer from @ pamubay here how to download images which was brilliant and the post from thenewdynamic on how to build pages from api link I tried to use airtable as CMS. I managed to create the pages but when I tried to download the images I got

error calling Content: error calling resources.GetRemote: failed to resolve media type for remote resource "https://dl.airtable.com/.attachments/bdb6fe067c6d9455177f8f3cd3857a85/f744922e/beer001.jpg"

the code that I used is

{{ $img := resources.GetRemote "https://dl.airtable.com/.attachments/bdb6fe067c6d9455177f8f3cd3857a85/f744922e/beer001.jpg" }}
{{ $img := $img.Content}}

<img src="{{ $img.RelPermalink }}">

I think that the problem is how the link from airtable is structured and Go haw a problem with that.

Does anybody has an idea?

Thanks

I don’t think so. Some servers do not send the correct MIME type for resources.

What happens if you try to pass the image media type manually?

For example with something like:

{{ resources.GetRemote $img (dict “type/subtype;” “image/jpeg”) }}

ref

The server is sending a content-type header (image/jpeg) based on the file extension. Hugo does some background checks to make sure we are receiving what the server says it is serving.

The image is a PNG file, not a JPEG. Someone mislabeled this file. With this construct you can warn instead of dying:

{{ with resources.GetRemote "https://dl.airtable.com/.attachments/bdb6fe067c6d9455177f8f3cd3857a85/f744922e/beer001.jpg" }}
  {{ with .Err }}
    {{ warnf "%s" . }}
  {{ else }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
  {{ end }}
{{ else }}
  {{ warnf "Unable to obtain remote image." }}
{{ end }}
1 Like

Thanks you were right. It worked. I uploaded the image as .png and it got downlaoded. Thank you very much.

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