Is there an API for uploading images to the StackExchange-specific imgur installation? I could use the main imgur site, but they don't keep the images indefinitely.

Use case: It would be advantageous to be able to rasterize graphics and upload them from Mathematica directly, especially since Mathematica-related questions/answers often need illustrations, and graphics are so tightly integrated into the Mathematica dev environment.

  • You basically need one thing: Stack Exchange's API key for imgur - which they are probably not likely to divulge. Commented Nov 8, 2011 at 1:12
  • @George Is that a "no" answer, i.e. this is currently not possible?
    – Szabolcs
    Commented Nov 8, 2011 at 9:51
  • I can't give an official answer as to whether this is planned or whatever - but as far as I can tell, no - this is not possible. Commented Nov 8, 2011 at 17:37
  • @GeorgeEdison, how does your red circle script (I forget the name of it) keep the images then? I thought you had used SE's imgur account?
    – Jonathan.
    Commented Nov 9, 2011 at 17:27
  • @Jonathan: No, it had its own hosting. Commented Nov 9, 2011 at 17:32

3 Answers 3


No, this is not available.

Something like it may be available in the V3.0 timeframe, but I can't commit to that at this time.

  • Would SE be alright with us doing, in effect, what the other answer says to do? So sending a POST request to /upload/image? Commented Nov 8, 2015 at 13:25

While this is not available I don't think SE can do much to prevent it. I don't have any easily readable code to give you code example, but the theory is following:

The upload request:

To upload images to Stack Exchange, you must send following POST request to https://__HOST__/upload/image:

fkey: we'll talk about this token later
source: web/computer

filename: the file data binary file, source must be computer
upload-url: url of target image, source must be web

The fkey token:

If you're logged in, the fkey token is in a hidden input field:

<input id="fkey" type="hidden" value="..." name="fkey">

If not, it can be parsed out of StackExchange.init() call:

preg_match("~StackExchange\.init\(([^;]+)\);~s", $html, $m)
$data = json_decode($m[1], true);

That's it. You don't even have to be logged on.

  • Thanks! The problem is that this might change/break any time without notice. This was the original motivation for the question. In fact it already broke once, then it was fixed.
    – Szabolcs
    Commented Nov 20, 2014 at 14:51
  • Yes, it's a hack, not an official way to do it. Commented Nov 20, 2014 at 14:54
  • 2
    Just do fkey().fkey in chat or StackExchange.options.user.fkey on main sites Commented Nov 8, 2015 at 13:26
  • fkey.value gives the result
    – amit jha
    Commented Feb 24, 2016 at 7:29
  • Also, is this fkey site specific?
    – amit jha
    Commented Feb 24, 2016 at 7:41

Please note: this does not work anymore since Mobile app infrastructure has been decommissioned.

There is sort of a workaround which my Broken Image Repairer script is already using. You do need an access token that is tied to one of the official Stack Exchange mobile apps, e.g. by using a proxy like mitmproxy to inspect traffic between the app on your smartphone and the API server.

You'll need to make a POST call to https://mobile.stackexchange.com/1/image/upload and supply the following parameters (as application/x-www-form-urlencoded):

  • access_token
  • key (the iOS app uses kJ1geZUa*oJVMN229qwESg((, the Android app r0aEx)wmOcRhhPMdffXeUQ(()
  • image_mime_type: image/png, image/jpeg or image/gif (other image types are not supported)
  • image_name: just a random string, doesn't really matter
  • filter: vqc7J (I have no idea which fields these correspond to, since this call is not documented)
  • image_data: the image data, encoded as Base64

If the upload succeeds, you'll get the URL back (the response is in the usual API style, a root object with an items array; there'll be a single item with a url property).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .