cagataygurturk / image-resizer-service

Serverless image resizing service for AWS
https://serverlessrepo.aws.amazon.com/#/applications/arn:aws:serverlessrepo:us-east-1:526515951862:applications~image-resizer-service
MIT License
101 stars 51 forks source link

Unable to open image #3

Closed ghost closed 5 years ago

ghost commented 6 years ago

It looks like #1 wasn't fixed with 0.1.1 after all.

I'm using the latest version (verified by redeploying and, separately, building and diffing against what the Lambda function code has).

2018-10-06T23:08:25.075Z ba15b78f-c9bc-11e8-933e-0fea3cb0308d ERROR 500 null { Error: Command failed: convert: unable to open image `/tmp/resized.[bucket].[path].600.NaN': No such file or directory @ error/blob.c/OpenBlob/2643.

at ChildProcess. (/var/task/index.js:1:5024) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) at maybeClose (internal/child_process.js:925:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) timedOut: false, killed: false, code: 1, signal: null }

There are similar errors when both width and height are supplied.

2018-10-06T23:12:15.425Z 435d25d8-c9bd-11e8-b440-87819a8ef2f0 ERROR 500 null { Error: Command failed: convert: unable to open image `/tmp/resized.[bucket].[path].600.600': No such file or directory @ error/blob.c/OpenBlob/2643.

at ChildProcess. (/var/task/index.js:1:5024) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) at maybeClose (internal/child_process.js:925:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) timedOut: false, killed: false, code: 1, signal: null }

ghost commented 6 years ago

Here's the complete set of logs for one request.

23:12:15 START RequestId: 435d25d8-c9bd-11e8-b440-87819a8ef2f0 Version: $LATEST 23:12:15 2018-10-06T23:12:15.109Z 435d25d8-c9bd-11e8-b440-87819a8ef2f0 INFO: key: [path] 23:12:15 2018-10-06T23:12:15.337Z 435d25d8-c9bd-11e8-b440-87819a8ef2f0 resize arg 23:12:15 2018-10-06T23:12:15.337Z 435d25d8-c9bd-11e8-b440-87819a8ef2f0 arg 600x600 23:12:15 2018-10-06T23:12:15.425Z 435d25d8-c9bd-11e8-b440-87819a8ef2f0 ERROR 500 null { Error: Command failed: convert: unable to open image `/tmp/resized.[bucket].[path].600.600': No such file or directory @ error/blob.c/OpenBlob/2643. at ChildProcess. (/var/task/index.js:1:5024) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) a 23:12:15 2018-10-06T23:12:15.425Z 435d25d8-c9bd-11e8-b440-87819a8ef2f0 {"errorMessage":"[object Object]"} 23:12:15 END RequestId: 435d25d8-c9bd-11e8-b440-87819a8ef2f0

eneam commented 6 years ago

The problem happens when the image is in a subfolder. A quick fix is to change in image.js the following line: const resizedFile = `${os.tmpDir}/resized.${imageBucket}.${objectKey}.${width}.${height}`; with: const normalizeObjectKey = objectKey.split('/').join('.'); const resizedFile = `${os.tmpDir}/resized.${imageBucket}.${normalizeObjectKey}.${width}.${height}`;