Created
July 30, 2014 16:56
-
-
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.
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
//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