Free Image Hosting with Analytics
Imgur is a great service to host images. It's free, simple, and it gives you neat analytics.
The only problem is, the current Imgur API doesn't allow you to upload images to the account you login with. Reason being, they use cookies to know what user to associate the uploaded image with. So if you want to programmatically upload images to Imgur, you have to pass the cookie key/value pair that it's looking for.
How to Find Cookies in Your Web Browser
Cookies, in case you're not totally sure, are just a hash of key/value pairs that the browser stores for a site. Sites can store any key/value pair in the cookie, and they do it to keep track of key things about you so the next time you visit the site they know it's you. A session on the other hand is a set of key/value pairs that only exists while your on the site; once you leave the site, the session is cleared, but the cookies remain.
In Imgur's case, they store a key called IMGURSESSION in your cookies, and we need to access that. Here's how to find the cookie in some browsers on a mac:
Find Cookies in Safari
- Go to "Safari > Preferences" on the menu bar.
- Click the "Security" tab.
- Click the "Show Cookies" button.
- Type "IMGURSESSION" into the search bar.
- Copy the "Content" column, the value for the IMGURSESSION key.
Find Cookies in Google Chrome
- Go to "Chrome > Preferences" on the menu bar.
- Click the "Under the Hood" tab.
- Click "Content settings..." in the "Privacy" section.
- On the "Cookies" tab, click "Show cookies and other site data".
- Type "imgur" into the search bar.
- Click "IMGURSESSION".
- Copy the "Content" field, the value for the IMGURSESSION key.
Find Cookies in Firefox (3.6)
- Go to "Tools > Page Info" (⌘I).
- Click the "Security" tab.
- Click "View Cookies".
- Click "IMGURSESSION".
- Copy the "Content" field for IMGURSESSION.
Upload Images to Your Account through the Imgur API
Now that you have the IMGURSESSION cookie value, you can upload to your imgur account. The problem currently is that if you went to http://imgur.com, logged in, and uploaded an image, it would be saved under http://your-username.imgur.com for easy access later... but then if you load an image with the API, it won't be there. That's why you need the cookie.
Here's the code for Ruby:
... or an easier to read RestClient version:
With something like that you can upload images to your imgur account programmatically.
