Want to Extract a Image

Hey,

Simple question…

I have a URL which has a image eg (https://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8dmlld3xlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80), Now i need only the Image from this URL and nothing else. I tried using HTML extractor node, but the Get method from this URL doesnt contain img tag. I need to know is there a way to get only the image from a URL and store that image as a variable for further processing ?

if yes, can some one help me with an example please.

I went through the HTML extractor doc but its not helping me to achive what i want.

Thanks,
Sathya

Hey @Sathya_Narayanan,

I had a quick look and that URL appears to be an image already so you can do it with something like this…

image

In the HTTP Request node set the response to File and if you check the binary data you will see your image.

From there it is just a case of using the Write Binary File node to output the file to the filesystem, There is a tricky bit though as there is no real filename or extension I have cheated a bit and used the replace function on the mimetype so it won’t be perfect but should get you started.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8dmlld3xlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80",
        "responseFormat": "file",
        "options": {},
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "fileName": "=/home/node/.n8n/{{$binary.data.fileName}}.{{$binary.data.mimeType.replace(\"image/\", \"\")}}"
      },
      "name": "Write Binary File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        640,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Good luck and happy automating.

1 Like

Hey,

That was quick and thanks for getting back on me…

yes, the URL is already a image , only after posting the example URL i checked and i found its already retrun an image…

However what i am trying to do is that, i am trying to capture image from slack and process it…

when i use a HTTP note to get a response on the Image which was posted on the slack, i get an URL and when i do a HTTP request to that URL all i get is a bunch of HTML dom, and i dont know how to process that…

the HTML reponse is big and i am unable to post it over here…

That sounds like it may be a more complicated, Can you share the workflow you are currently using (replacing anything important) and I can take a quick look unless anyone beats me to it.

1 Like

Hey Jon,

After lot of struggle i managed to get what i want…

For those of who having the same query, you have to first make the slack image to a public_enabled. This is achiveable using the slack API files.sharedPublicURL

Now that i have done it and i also found a way to get the exact image by modifying the permalink_public URL.

Alrite, right now i have the link which is like this - https://slack-files.com/T01C6GMHN8Z-F02GX8X3TDM-e940fXXXXX

Now i have to modify this link to something else which is - https://slack-files.com/files-pri/T01C6GMHN8Z-F02GX8X3TDM/image.png?pub_secret=e940f65XXX

How can i do that in N8N. Please help.

1 Like

I will have to have a proper look at that one tomorrow, what are you using to get the messages from Slack is it the event API?

Yes its event api, I kind of made some workaround to get the expected result using set node with regular expression, but I not sure that’s the right way to do it …

I M kind of looking out for some better options…

Which event are you subscribed to?

Have you tried using the file option to get the information to see if it reruns the private download url?

Hi Jon,

In the Event it does shows the private download URL, but the problem is, you cannot send that URL to external source…

The whole purpus of this automation is to grab the image from slack and post that to our internal ticketing tool as notes…

In order to do so, we have to convert the URL to a publicly accessiable and then convert the URL to a direct image link and post it…

This solution was provided by slack …

That sounds like a lot of work, which event are you subscribed to?