Skip to content

Instantly share code, notes, and snippets.

@Acorn-zz
Created July 2, 2011 05:20
Show Gist options
  • Save Acorn-zz/1059755 to your computer and use it in GitHub Desktop.
Save Acorn-zz/1059755 to your computer and use it in GitHub Desktop.
Upload image to imgur using YQL
# 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