I am working on a face recognition API that accept only image URL .
I want to generate a image URL from image of my local computer in python .Any solution to generate the image URL in python ? so I can pass the image URL in to API (that only take image URL).
Here is my code :
import requests # put your keys in the header headers = { "app_id": "4353454", "app_key": "5474565rfedgry564353tgtr" } #here I want to convert the image to image URL so I can easily pass it as a argument into API payload = '{"image":"image_URL"}' url = "url_of_API" r = requests.post(url, data= payload, headers=headers) print(r.content)
Any solution will highly appreciated .
Advertisement
Answer
If you want to send the URLs to external APIs, your images need to be hosted somewhere. If your machine is communicating locally, you can simply run
python -m http.server
in your images folder. Then you will get URLs like
127.0.0.1:8000/myImg.png
To access this on another machine in same network, the url would be:
IPv4ofMachine:8000/myImg.png
You can get IPv4 of the host machine by running “ipconfig” in your CMD.
Now, if you want to communicate with external host/ API Services which is asking for image URL, you have to host those image somewhere. I would suggest AWS S3 buckets. It is really easy and free to use. By uploading it there, you will get a clear URL of your images which further can be used on web.