vendredi 24 juillet 2015

Why S3 only stores the last item of my loop?

I'm trying to use the node AWS SDK for uploading images but I have a problem when I'm using loop.

Here's my node module :

gm = require('gm').subClass imageMagick: true
s3 = require '../../modules/s3'
Photo = require '../../models/Photo'
sizes =
  t: 100
  m: 240
  z: 640
  l: 1024
  k: 2048
newPhoto = new Photo
newPhotoImg = gm process.cwd() + '/' + req.files.file.path
for key, val of sizes
  newPhotoImg
  .resize(null, val)
  .toBuffer 'jpg', (err, buffer) ->
    if err then console.error err and res.status(500).end() else
      params =
        Key: newPhoto.id + '-' + key + '.jpg'
        Body: buffer
        ContentType: 'image/jpeg'
      s3.putObject params, (err, data) ->
        if err then console.error err else console.log data

My s3 module works well and it is most probably not part of the problem.

The issue is I have a ETag returned for each size but when I look in my S3 Management Console, only the last item of loop (with the size 'k') is stored.

Can someone help me please ?




Aucun commentaire:

Enregistrer un commentaire