With visual testing we occasionally need to debug images in CI environments. We were previously using Imgur's v1 API:
but that's been shutdown and v2 and v3 seems like they need login for uploading images. We don't like that since these are rarely setup and we don't want to associate development content with personal content.
Thankfully Imgur supports uploading images via the browser without logging in. After trial/error, we got the following script for uploading a single image:
#!/usr/bin/env bash
# Exit on first error
set -e
# Define our filepath and filename
filename="path/to/my/file.png"
content_type="image/png"
# path/to/my/file.png -> file.png
filename="$(basename filepath)"
curl -X POST "http://imgur.com/upload" \
-H "Referer: http://imgur.com/upload" \
-F "Filedata=@\"$filepath\";filename=$filename;type=$content_type"
# Response: {"data":{"hashes":["1YZD9eY"],"hash":"1YZD9eY","deletehash":"XA3NaYKvzQrGnCn","album":false,"edit":false,"gallery":null,"animated":false,"height":10,"width":10,"ext":".png"},"success":true,"status":200}
# Image URL: http://imgur.com/1YZD9eY
One drawback of this approach is we don't have cookies so we cannot properly delete the image =(
We could use a curl
cookie jar but it's easier said than done to transfer that out of CI
Seems outdated, there's some JS manipulation now, or I'm not woke up