Created
July 26, 2015 05:18
-
-
Save yutin1987/112bae184b0bf0480274 to your computer and use it in GitHub Desktop.
Parse.com upload image to imgur
This file contains 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
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