mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #1197 from halfdan/994-image-uploads
Show proper error message when image upload fails
This commit is contained in:
commit
2d1e28335c
3 changed files with 15 additions and 8 deletions
|
@ -93,6 +93,13 @@
|
|||
fail: function (e, data) {
|
||||
$dropzone.trigger("uploadfailure", [data.result]);
|
||||
$dropzone.find('.js-upload-progress-bar').addClass('fail');
|
||||
if (data.jqXHR.status === 413) {
|
||||
$dropzone.find('div.js-fail').text("The image you uploaded was too big.");
|
||||
} else if (data.jqXHR.status === 415) {
|
||||
$dropzone.find('div.js-fail').text("The image type you uploaded is not supported. Please use .PNG, .JPG, .GIF.");
|
||||
} else {
|
||||
$dropzone.find('div.js-fail').text("Something went wrong :(");
|
||||
}
|
||||
$dropzone.find('div.js-fail, button.js-fail').fadeIn(1500);
|
||||
$dropzone.find('button.js-fail').on('click', function () {
|
||||
$dropzone.css({minHeight: 0});
|
||||
|
@ -231,4 +238,4 @@
|
|||
ui.init();
|
||||
});
|
||||
};
|
||||
}(jQuery));
|
||||
}(jQuery));
|
||||
|
|
|
@ -114,7 +114,7 @@ adminControllers = {
|
|||
renameFile(filename);
|
||||
});
|
||||
} else {
|
||||
res.send(403, 'Invalid file type');
|
||||
res.send(415, 'Unsupported Media Type');
|
||||
}
|
||||
},
|
||||
'login': function (req, res) {
|
||||
|
|
|
@ -31,26 +31,26 @@ describe('Admin Controller', function() {
|
|||
});
|
||||
|
||||
describe('can not upload invalid file', function() {
|
||||
it('should return 403 for invalid file type', function() {
|
||||
it('should return 415 for invalid file type', function() {
|
||||
res.send = sinon.stub();
|
||||
req.files.uploadimage.name = 'INVALID.FILE';
|
||||
req.files.uploadimage.type = 'application/octet-stream'
|
||||
admin.uploader(req, res);
|
||||
res.send.calledOnce.should.be.true;
|
||||
res.send.args[0][0].should.equal(403);
|
||||
res.send.args[0][1].should.equal('Invalid file type');
|
||||
res.send.args[0][0].should.equal(415);
|
||||
res.send.args[0][1].should.equal('Unsupported Media Type');
|
||||
});
|
||||
});
|
||||
|
||||
describe('can not upload file with valid extension but invalid type', function() {
|
||||
it('should return 403 for invalid file type', function() {
|
||||
it('should return 415 for invalid file type', function() {
|
||||
res.send = sinon.stub();
|
||||
req.files.uploadimage.name = 'INVALID.jpg';
|
||||
req.files.uploadimage.type = 'application/octet-stream'
|
||||
admin.uploader(req, res);
|
||||
res.send.calledOnce.should.be.true;
|
||||
res.send.args[0][0].should.equal(403);
|
||||
res.send.args[0][1].should.equal('Invalid file type');
|
||||
res.send.args[0][0].should.equal(415);
|
||||
res.send.args[0][1].should.equal('Unsupported Media Type');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue