chikadance
chikadance

Reputation: 4147

How to use google search by image in curl

I successfully do it with following:

<html>
<body>
<form action="https://www.google.com/searchbyimage/upload" METHOD="POST" enctype="multipart/form-data">
  <input type="file" name="encoded_image">
  <input type="Submit" name="sch" value="sch">
</form>
</body>
</html>

when i select ~/Dropbox/img/green.jpg, and click "sch", it auto redirect to correct google result

enter image description here

but when i use following:

curl -i -F name=green.jpg -F filedata=@/home/roroco/Dropbox/img/green.jpg https://www.google.com/searchbyimage/upload

the google result show:

enter image description here

I hope search by image in curl how to do it?

Upvotes: 3

Views: 2130

Answers (2)

chikadance
chikadance

Reputation: 4147

@xorspark is right, I should use following code:

curl -i -F sch=sch -F encoded_image=@path/to/my/imagefile.jpg https://www.google.com/searchbyimage/upload

I wanna tell everybody how to find the name "encoded_image", in google image search page, when i click camera icon > upload an image, the form has name "encoded_image" like following:

enter image description here

Upvotes: 0

xorspark
xorspark

Reputation: 16012

Your form names don't match the values google image search is looking for. Your working test HTML file is submitting the file in encoded_image and is also providing sch from the input button, but you're submitting the file in filedata and a name in your curl command.

This is what worked for me locally:

curl -i -F sch=sch -F encoded_image=@path/to/my/imagefile.jpg https://www.google.com/searchbyimage/upload

It also works without providing sch but I kept it to be consistent with your original form.

Upvotes: 6

Related Questions