When sending an upload request with the HTTParty Ruby gem, I keep receiving the error 1001, "Image failed to upload". I have tried setting the image POST field to an @-prefixed path and a URL, both get the same error.
Also, when mixing in HTTParty to my Imgur class with include HTTParty, and calling with self.class.post instead of HTTParty.post requests to upload.json yield an XML response instead of the expected JSON. Of course, the upload still doesn't work.
Posting images from Google AppEngine? immediately runs into "Upload limit reached", presumably because of the IP address based rate limiting, given that Google AppEngine? uses a limited set of IP addresses, and that there are potentially many AppEngine? apps using the imgur api. Could you please support rate limiting based on api key, rather than IP address? Thanks!
I don't agree with limiting the API key at all. There are some applications I'm developing (dashboard widget and dock/standalong droplet) to upload images and would hate to see the 100+ users get limited based on the API key alone. Perhaps a combination threshold somehow where both have to be exceeded.
The upload API has a daily and hourly upload limit for any given IP address. A single IP address is able to upload 50 images an hour and 200 images a day. If you need to use the Google app engine, just shoot me an email at alan@imgur.com
I'm finally working on my upload application which is in C# and it's going just fine @ person above me. Must be building your headers improperly or not sending the file data properly.
I'm also looking at adding imgur account support to our product, Upshot. It seems like it would be a nice feature. Imageshack and Twitpic support uploading to a user's account.
I agree with Andy. Now I have to send imgur address of uploaded image somewhere because it is not practical to copy it by symbol from mobile phone screen.
I spent quite a while trying to figure out why I could't put BASE64_ENCODED_STRING as the image parameter and then set the body of the post to be the actual data ;)
On a related note, it would be great to be able to send the data in the body of the post. Perhaps if image=SOME_CONSTANT it could imply that the data was in the body of the post? Sounds silly, but some Java folk would likely appreciate it.
Replying to my previous comment, it turns out that my last sentence was ill-informed. Hopefully posting this makes up for it ;)
Here is a Java example of uploading to imgur. Using mime4j and httpmime, available from here and here,respectively. To get httpmime, just download httpclient. The httpmime jar is included
// Create the post
HttpPost hp = new HttpPost(IMGUR_POST_URI);
MultipartEntity en = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
HttpClient c = new DefaultHttpClient();
HttpResponse r;
String xmlResponse = null;
try {
en.addPart("key", new StringBody(IMGUR_API_KEY));
en.addPart("image", new InputStreamBody(is, null)); // or use new FileBody(File . . . )
hp.setEntity(en);
r = c.execute(hp);
// Might be nice to show an error message if the status code is ever
// not 200
// int code = r.getStatusLine().getStatusCode();
// Read in the response
InputStream content = r.getEntity().getContent();
ByteArrayOutputStream response = new ByteArrayOutputStream();
final int BUF_SIZE = 1 << 8; // 1KiB buffer
byte[] buffer = new byte[BUF_SIZE];
int bytesRead = -1;
while ((bytesRead = content.read(buffer)) > -1) {
response.write(buffer, 0, bytesRead);
}
content.close();
xmlResponse = response.toString();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}}
Seems that Imgur might use this to detect files versus URLs in the image parameters. At least, that's the only explanation that I can think of. Anyways, using null for the parameter doesn't work, while using some filename does
in AS3/Flex you can send an image object in a given format (in this example PNG encoded.)
protected function imgur():void
{
try
{
var imgurUrl:String = "http://imgur.com/api/upload.xml";
var keyImgur:String = "YOUR IMGUR API KEY GOES HERE";
var b:BitmapData = Clipboard.generalClipboard.getData(ClipboardFormats.BITMAP_FORMAT) as BitmapData;
var pngEnc:PNGEncoder = new PNGEncoder();
var byteArray:ByteArray = pngEnc.encode(b);
var b64:Base64Encoder = new Base64Encoder();
b64.encodeBytes(byteArray);
var imgBase64:String = b64.toString();
var request:URLRequest = new URLRequest(imgurUrl)
request.method = URLRequestMethod.POST;
request.data = new URLVariables();
request.data.key = keyImgur;
request.data.image = imgBase64;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, imgurResult);
loader.load(request);
}
catch (error:Error)
{
}
}
protected function imgurResult(e:Event):void
{
var xml:XML = new XML((e.target as URLLoader).data);
var page:String = xml.imgur_page;
var delete:String = xml.delete_page;
}
When sending an upload request with the HTTParty Ruby gem, I keep receiving the error 1001, "Image failed to upload". I have tried setting the image POST field to an @-prefixed path and a URL, both get the same error.
Here's the exact code I'm using:
require 'HTTParty' HTTParty.post("http://imgur.com/api/upload.json", { :query => { :key => "bf880aa11869154f1772cea2d3bdcc31", :image => "http://media.fukung.net/images/20568/4e808393622518e616761bc4a4362f69.jpg" } })Also, when mixing in HTTParty to my Imgur class with include HTTParty, and calling with self.class.post instead of HTTParty.post requests to upload.json yield an XML response instead of the expected JSON. Of course, the upload still doesn't work.
Posting images from Google AppEngine? immediately runs into "Upload limit reached", presumably because of the IP address based rate limiting, given that Google AppEngine? uses a limited set of IP addresses, and that there are potentially many AppEngine? apps using the imgur api. Could you please support rate limiting based on api key, rather than IP address? Thanks!
I don't agree with limiting the API key at all. There are some applications I'm developing (dashboard widget and dock/standalong droplet) to upload images and would hate to see the 100+ users get limited based on the API key alone. Perhaps a combination threshold somehow where both have to be exceeded.
The upload API has a daily and hourly upload limit for any given IP address. A single IP address is able to upload 50 images an hour and 200 images a day. If you need to use the Google app engine, just shoot me an email at alan@imgur.com
I'm finally working on my upload application which is in C# and it's going just fine @ person above me. Must be building your headers improperly or not sending the file data properly.
Any plans on making it possible to upload to imgur accounts via the API?
hi,
i have some problems with the php example i get always the error: 1015No API key was sent
i use the complete example from above and i have set the api key that i get from you.
where is the problem? can anybody help me?
ok i get it work. here is the php code that i used.
<?
// curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
?>
i commented the part with http_build_query out and the line with the CURLOPT_HTTPHEADER too. and now it works
>>Any plans on making it possible to upload to imgur accounts via the API?
x2
>> >>Any plans on making it possible to upload to imgur accounts via the API?
>> x2
I'd like that too :)
I'm also looking at adding imgur account support to our product, Upshot. It seems like it would be a nice feature. Imageshack and Twitpic support uploading to a user's account.
I agree with Andy. Now I have to send imgur address of uploaded image somewhere because it is not practical to copy it by symbol from mobile phone screen.
Could we change the line that reads:
# OR: ("image", "BASE64_ENCODED_STRING"))]To read something more like
# OR: ("image", "/9j/4ABAAD/2wCEAAkG . . . (Insert your Base64 encoded string here)"))]I spent quite a while trying to figure out why I could't put BASE64_ENCODED_STRING as the image parameter and then set the body of the post to be the actual data ;)
On a related note, it would be great to be able to send the data in the body of the post. Perhaps if image=SOME_CONSTANT it could imply that the data was in the body of the post? Sounds silly, but some Java folk would likely appreciate it.
Replying to my previous comment, it turns out that my last sentence was ill-informed. Hopefully posting this makes up for it ;)
Here is a Java example of uploading to imgur. Using mime4j and httpmime, available from here and here,respectively. To get httpmime, just download httpclient. The httpmime jar is included
// Create the post HttpPost hp = new HttpPost(IMGUR_POST_URI); MultipartEntity en = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE); HttpClient c = new DefaultHttpClient(); HttpResponse r; String xmlResponse = null; try { en.addPart("key", new StringBody(IMGUR_API_KEY)); en.addPart("image", new InputStreamBody(is, null)); // or use new FileBody(File . . . ) hp.setEntity(en); r = c.execute(hp); // Might be nice to show an error message if the status code is ever // not 200 // int code = r.getStatusLine().getStatusCode(); // Read in the response InputStream content = r.getEntity().getContent(); ByteArrayOutputStream response = new ByteArrayOutputStream(); final int BUF_SIZE = 1 << 8; // 1KiB buffer byte[] buffer = new byte[BUF_SIZE]; int bytesRead = -1; while ((bytesRead = content.read(buffer)) > -1) { response.write(buffer, 0, bytesRead); } content.close(); xmlResponse = response.toString(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }}Sigh...not my day. In my previous post (the Java example) it seems to be wise to NOT pass null as the second argument in
en.addPart("image", new InputStreamBody(is, null));instead, putting any filename there seems to do the trick
en.addPart("image", new InputStreamBody(is, "any-filename-you-want"));I would assume this is because it slightly changes the headers sent with that part of the form. This
becomes
Seems that Imgur might use this to detect files versus URLs in the image parameters. At least, that's the only explanation that I can think of. Anyways, using null for the parameter doesn't work, while using some filename does
AS3 implementation demo
in AS3/Flex you can send an image object in a given format (in this example PNG encoded.)
protected function imgur():void { try { var imgurUrl:String = "http://imgur.com/api/upload.xml"; var keyImgur:String = "YOUR IMGUR API KEY GOES HERE"; var b:BitmapData = Clipboard.generalClipboard.getData(ClipboardFormats.BITMAP_FORMAT) as BitmapData; var pngEnc:PNGEncoder = new PNGEncoder(); var byteArray:ByteArray = pngEnc.encode(b); var b64:Base64Encoder = new Base64Encoder(); b64.encodeBytes(byteArray); var imgBase64:String = b64.toString(); var request:URLRequest = new URLRequest(imgurUrl) request.method = URLRequestMethod.POST; request.data = new URLVariables(); request.data.key = keyImgur; request.data.image = imgBase64; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, imgurResult); loader.load(request); } catch (error:Error) { } } protected function imgurResult(e:Event):void { var xml:XML = new XML((e.target as URLLoader).data); var page:String = xml.imgur_page; var delete:String = xml.delete_page; }note: the result var delete is a reserved word, so won't work. (just use something else)
im getting the error: wrong file type, I'm trying to upload a local image like so:
local values = { key = "f77d0b8cd41eb62792be0bf303e649df", image = "C:\Users\Name\Desktop\Program Manager.png" } success = HTTP.Submit("http://imgur.com/api/upload.xml", values, SUBMITWEB_POST, 20, 80, nil, nil);This is lua btw.
>> >>Any plans on making it possible to upload to imgur accounts via the API?
This would be incredibly useful. I wasn't able to find an Android client with imgur account support, and this is probably why.
Please consider adding this to the API. Thank you!
in python when performing c.perform() ,how do we catch the responding json/xml? json=c.perform() doesnt work!
Thanks :D
Como hago para ver las imamgenes subidas desde la api?