Skip to content

Instantly share code, notes, and snippets.

@yutin1987
Created July 26, 2015 05:18
Show Gist options
  • Save yutin1987/112bae184b0bf0480274 to your computer and use it in GitHub Desktop.
Save yutin1987/112bae184b0bf0480274 to your computer and use it in GitHub Desktop.
Parse.com upload image to imgur
Parse.Cloud.afterSave($className, function(request) {
var image = request.object.get('image');
if (image) {
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://api.imgur.com/3/upload',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Client-ID ' + $clientId
},
body: {
type: 'url',
image: image.url()
},
success: function(httpResponse) {
console.log(httpResponse.data.data.link);
request.object.save({
'imageUrl': httpResponse.data.data.link
});
},
error: function(error) {
console.log(error);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment