Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
You basically need one thing: Stack Exchange's API key for imgur - which they are probably not likely to divulge. – Nathan Osman Nov 8 '11 at 1:12
@George Is that a "no" answer, i.e. this is currently not possible? – Szabolcs Nov 8 '11 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. – Nathan Osman Nov 8 '11 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. Nov 9 '11 at 17:27
@Jonathan: No, it had its own hosting. – Nathan Osman Nov 9 '11 at 17:32
up vote 4 down vote accepted

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.

share|improve this answer
Would SE be alright with us doing, in effect, what the other answer says to do? So sending a POST request to /upload/image? – ᔕᖺᘎᕊ Nov 8 '15 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 http://__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.

share|improve this answer
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 Nov 20 '14 at 14:51
Yes, it's a hack, not an official way to do it. – Tomáš Zato Nov 20 '14 at 14:54
Just do fkey().fkey in chat or StackExchange.options.user.fkey on main sites – Unity 3D Nov 8 '15 at 13:26
fkey.value gives the result – amit jha Feb 24 at 7:29
Also, is this fkey site specific? – amit jha Feb 24 at 7:41

You must log in to answer this question.

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