Created
July 2, 2011 05:20
-
-
Save Acorn-zz/1059755 to your computer and use it in GitHub Desktop.
Upload image to imgur using YQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes an image URL and uploads it to imgur.com, calling the callback with the resulting image URL | |
urlToImgur = (url, callback) -> | |
upload_url = "http://api.imgur.com/2/upload?url=#{url}" | |
$.ajax | |
url: 'http://query.yahooapis.com/v1/public/yql' | |
dataType: 'jsonp' | |
data: { | |
q: "select none from html where url='#{upload_url}'" | |
diagnostics: true | |
} | |
success: (data) -> | |
redirects = data.query.diagnostics.redirect | |
image_url = redirects[redirects.length-1].content | |
callback image_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment