Skip to content
Browse files

Reject files which are not images

  • Loading branch information...
1 parent 97ee6fc commit 9e79fb2eaa40878a3037499dfb68668b44af5082 ciberch committed Sep 14, 2012
Showing with 11 additions and 5 deletions.
  1. +6 −2 public/js/backbone/activity_create_view.js
  2. +5 −3 server.js
View
8 public/js/backbone/activity_create_view.js
@@ -33,8 +33,12 @@ var ActivityCreateView = Backbone.View.extend({
if(!actData.object.image) {
var actView = this;
$('#new_photo').ajaxForm(function(data) {
- actView.model.set('object', data.object);
- actView.render();
+ if (data && data.object && data.object.objectType == "photo") {
+ actView.model.set('object', data.object);
+ actView.render();
+ } else {
+ alert("File rejected. Please check its a valid image.")
+ }
});
}
View
8 server.js
@@ -278,7 +278,7 @@ function reducePhoto(req, res, next){
function ingestPhoto(req, res, next){
if (req.files.image) {
im.identify(req.files.image.path, function(err, features){
- if (features && features.width) {
+ if (features && features.width && features.format) {
var guid = Guid.create();
var fileId = guid + '/' + req.files.image.name;
var gs = asmsClient.streamLib.GridStore(asmsClient.streamLib.realMongoDB, fileId, "w", {
@@ -308,8 +308,10 @@ function ingestPhoto(req, res, next){
}
});
} else {
- if (err) throw err;
- throw(new Error("Cannot get width for photo"));
+ if (err)
+ next(err);
+ else
+ next(new Error("Cannot get width for photo -- this may be a bad file"));
}
});
} else {

0 comments on commit 9e79fb2

Please sign in to comment.
Something went wrong with that request. Please try again.