I am trying to upload an image on imgur by accessing their API through CURL. I tried:
curl -d "image=reddit.png" -d "key=myapikey" http://api.imgur.com/2/upload.json
It raised a famous error:
{"error":{"message":"Image format not supported, or image is corrupt.","request":"\/\/2\/upload.json","method":"post","format":"json","parameters":"image = reddit.png, key = myapikey"}}
I am also facing the same issue while writing a simple bash script
#!/bin/bash
API_KEY="myapikey"
file="$1"
output=$(curl -d "image=$file" -d "key=$API_KEY" http://api.imgur.com/2/upload.json)
echo $output
The ouytput is the same error message as above. I tried it with jpg/png
both format raised the same error.
So, any idea what am I doing wrong here.
PS: My imnage is not corrupt and I am executing the script/command from the same directory which contains the image.
Try this:
$ curl -d "image=@reddit.png" ...
See the manpage of curl for details and read the description of the -d --data
option.
Edit:
To encode an image, use the base64
utility:
$ base64 reddit.png > reddit.base64.png