ysugimoto/aws-lambda-image

Preserve file path in latest version

tusharvikky opened this issue · 7 comments

Hello,

File uploaded in foo/bar/image.png then it would be best if the resized images were added to /resized/small/foo/bar/image.png instead of the current behavior of putting it in foo/bar/resized/image.png

Hello @ysugimoto I was trying to replicate this in latest build. But couldn't get it to work.

Any help would be great.

Earlier issue #59

Hi @tusharvikky , I'll investigate that.

BTW, can I see your configuration, please?

Hey,

I was using the sample config. But my path of file upload is images/<someid>/<someid2>/timestamp.jpg

I have a S3 event handler in place on images folder.

Current output with below config:
reduced/timestamp.jpg and
resized/500-jpeg/timestamp.jpg

I'm expecting:
reduced/images/<someid>/<someid2>/timestamp.jpg -> Reduction block, I have added an absolute path of reduced.
resized/500-jpeg/images/<someid>/<someid2>/timestamp.jpg -> resized/500-jpeg added as absolute.

{
  "bucket": "bucketprod1-s01",
  "reduce": {
      "directory": "reduced",
      "quality": 70,
      "acl": "public-read",
      "cacheControl": "public, max-age=31536000"
  },
  "resizes": [
    {
      "size": 500,
      "directory": "resized/500-jpeg",
      "format": "jpg",
      "background": "white",
      "changeExtension": true
    }
  ]
}

@ysugimoto Did you got the time to look into this?

@tusharvikky Hi, I'm late.

I tested with the following config:

{
  "bucket": "testing-bucket",
  "reduce": {
      "directory": "./reduced",
      "quality": 90,
      "acl": "public-read",
      "cacheControl": "public, max-age=31536000"
  },
  "resizes": [
    {
      "size": 600,
      "directory": "./resized/600-jpeg",
      "format": "jpg",
      "background": "white",
      "changeExtension": true
    },
    {
      "size": 600,
      "directory": "/root/resized/600-jpeg",
      "format": "jpg",
      "background": "white",
      "changeExtension": true
    },
    {
      "size": 500,
      "directory": "resized/500-jpeg",
      "format": "jpg",
      "background": "white",
      "changeExtension": true
    }
  ]
}

And uploaded to original/example.png which is set S3 event. Then Lambda logs are:

Downloading: original/example.png
Reducing to: ./reduced
Uploading to: original/reduced/example.png (77141 bytes)
Resizing to: ./resized/600-jpeg
Reducing to: ./resized/600-jpeg
Uploading to: original/resized/600-jpeg/example.jpg (16881 bytes)
Resizing to: /root/resized/600-jpeg
Reducing to: /root/resized/600-jpeg
Uploading to: /root/resized/600-jpeg/example.jpg (16881 bytes)
Resizing to: resized/500-jpeg
Reducing to: resized/500-jpeg
Uploading to: resized/500-jpeg/example.jpg (12297 bytes)

It works as expected, I think. Because this package deals with image the only filename, not dealing directory of a filename. So if you want to consider about uploaded directory like <someId>, probably this pakcage should improve for dealing it.

@ysugimoto I'm a beginner in nodeJS, if you can point me out on how I can get it done, I can raise a pull request.

@tusharvikky Sorry for the late reply.

Well, now processed image path is generated at here, so you can deal with image directory someways.

I think it's better to add more option like keepDirectoryPath or something and treat file path by that option value is true or not for backward compatibility.

@kdybicz If you have any suggestions, plz tell us.

if we don't have any progress, close temporarily.