diff --git a/ghost/core/core/server/api/endpoints/images.js b/ghost/core/core/server/api/endpoints/images.js index 7b6fc2d26bdb..e2c26718587a 100644 --- a/ghost/core/core/server/api/endpoints/images.js +++ b/ghost/core/core/server/api/endpoints/images.js @@ -33,7 +33,12 @@ module.exports = { width: config.get('imageOptimization:defaultMaxWidth') }, imageOptimizationOptions); - await imageTransform.resizeFromPath(options); + try { + await imageTransform.resizeFromPath(options); + } catch (err) { + // If the image processing fails, we just want to store the original image + return store.save(frame.file); + } // Store the processed/optimized image const processedImageUrl = await store.save({ diff --git a/ghost/core/test/e2e-api/admin/images.test.js b/ghost/core/test/e2e-api/admin/images.test.js index 8d6467e7aa1d..e5f08322de7d 100644 --- a/ghost/core/test/e2e-api/admin/images.test.js +++ b/ghost/core/test/e2e-api/admin/images.test.js @@ -301,4 +301,14 @@ describe('Images API', function () { await uploadImageCheck({path: originalFilePath, filename: 'a.png', contentType: 'image/png'}); clock.restore(); }); + + it('Does not return HTTP 500 when image processing fails', async function () { + sinon.stub(imageTransform, 'resizeFromPath').rejects(new Error('Image processing failed')); + + const originalFilePath = p.join(__dirname, '/../../utils/fixtures/images/ghost-logo.png'); + const fileContents = await fs.readFile(originalFilePath); + + await uploadImageRequest({fileContents, filename: 'test.png', contentType: 'image/png'}) + .expectStatus(201); + }); });