Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

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

2 Answers 2

up vote 1 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

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 at 14:51
    
Yes, it's a hack, not an official way to do it. –  Tomáš Zato Nov 20 at 14:54

You must log in to answer this question.

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