Skip to content

Instantly share code, notes, and snippets.

@daviddoran
Created July 30, 2014 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviddoran/21c7efb78c4bb3bd21ce to your computer and use it in GitHub Desktop.
Save daviddoran/21c7efb78c4bb3bd21ce to your computer and use it in GitHub Desktop.
A Parse beforeSave callback that can be used to check that an uploaded image is not empty.
//Change 'Post' to the name of your class
Parse.Cloud.beforeSave('Post', function(request, response) {
//Change 'file' to the name of the column containing the image
var imageUrl = request.object.get('file').url();
Parse.Cloud.httpRequest({
url: imageUrl
}).then(function(httpResponse) {
if (!(httpResponse.buffer && httpResponse.buffer.length)) {
response.error('Uploaded image was empty or invalid');
} else {
response.success();
}
}, function (error) {
response.error('An error occurred checking uploaded image');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment