My favorites | Sign in
Project Home Wiki
Search
for
ImageUploading  

This documentation has moved to http://api.imgur.com

Comment by justin.d...@gmail.com, Oct 15, 2009

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" } })
Comment by justin.d...@gmail.com, Oct 15, 2009

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.

Comment by scot...@gmail.com, Oct 20, 2009

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!

Comment by unixg...@gmail.com, Oct 21, 2009

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.

Comment by project member mrgrim...@gmail.com, Nov 28, 2009

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

Comment by zer...@gmail.com, Dec 14, 2009

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.

Comment by riku.lin...@gmail.com, Jan 11, 2010

Any plans on making it possible to upload to imgur accounts via the API?

Comment by deluxest...@googlemail.com, Jan 23, 2010

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?

Comment by deluxest...@googlemail.com, Jan 23, 2010

ok i get it work. here is the php code that i used.

<?

$filename = "C:/.../Desert.jpg"; $handle = fopen($filename, "r"); $data = fread($handle, filesize($filename));

// $data is file data $pvars = array('image' => base64_encode($data), 'key' => '...'); $timeout = 30; $curl = curl_init(); $post = $pvars; //$post = http_build_query($pvars);
curl_setopt($curl, CURLOPT_URL, 'http://imgur.com/api/upload.xml'); curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post);

// curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));

$xml = curl_exec($curl);
curl_close ($curl);

?>

i commented the part with http_build_query out and the line with the CURLOPT_HTTPHEADER too. and now it works

Comment by duhbl...@gmail.com, May 7, 2010

>>Any plans on making it possible to upload to imgur accounts via the API?

x2

Comment by ivan.kanak, May 7, 2010

>> >>Any plans on making it possible to upload to imgur accounts via the API?

>> x2

I'd like that too :)

Comment by andy.ko...@gmail.com, May 11, 2010

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.

Comment by dalius.d...@gmail.com, May 16, 2010

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.

Comment by hamiltont, Jun 19, 2010

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.

Comment by hamiltont, Jun 25, 2010

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();
		}

}}
Comment by hamiltont, Jun 26, 2010

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

Content-Disposition: form-data; name="image";
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

becomes

Content-Disposition: form-data; name="image"; filename="any-filename-you-want"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

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

Comment by jason...@gmail.com, Jul 4, 2010

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;
    }
Comment by jason...@gmail.com, Jul 4, 2010

note: the result var delete is a reserved word, so won't work. (just use something else)

Comment by cglove...@gmail.com, Jul 10, 2010

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.

Comment by john.m...@gmail.com, Sep 19, 2010

>> >>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!

Comment by sridarsh...@gmail.com, Jan 1, 2011

in python when performing c.perform() ,how do we catch the responding json/xml? json=c.perform() doesnt work!

Comment by aum...@gmail.com, Jan 15, 2011

Thanks :D

Comment by Hackcrac...@gmail.com, Jun 1, 2011

Como hago para ver las imamgenes subidas desde la api?

Comment by deepakpa...@gmail.com, Feb 10, 2013

Hey suppose i am using this api for uploading the image to imgur from my PC can anyone tell me the basic steps that i need to follow to 1. upload image 2. getting direct link of an uploaded image

please reply


Sign in to add a comment
Powered by Google Project Hosting