Check is image url is an image?

I am return in array of images from web pages and using the the first image to post to facebook.

{{ $json.message.content.ProductImagesArray[0] }}

Sometimes the image url is in correct. How do I say:

If {{ $json.message.content.ProductImagesArray[0] }} is false use https:///www.mywebsite/newsItem.png

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Steve_Warburton , what does “image url is in correct” imply? Do you mean it has something different then ending with something like “.png” or “.jpg”? Could you be me specific and maybe give us some examples of an incorrect URL? Secondly, what “newsItem.png” should be for different wrong URL, is it always the same?

I have added another http node and added the image url.

{{ $json.message.content.ProductImagesArray[0] }}

In settings I added continue with url errors.
Change method to header

Then use a set node to change the value of url

{{ $(‘OpenAI2’).item.json.message.content.ProductImagesArray[0] ? $(‘OpenAI2’).item.json.message.content.ProductImagesArray[0] : ‘https://www.rockstruck.com/videoThumbnails/logo20.png’ }}

So if the initial request does not bring a url or the url is wrong I post a std image.

1 Like

Thanks @Steve_Warburton , there is a simpler expression that might work the same. It could look like below

{{ $('OpenAI2').item.json.message.content.ProductImagesArray?.[0] ?? 'https://www.rockstruck.com/videoThumbnails/logo20.png' }}

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