dimanche 28 juin 2015

AngularJS AWS S3 sdk putObject won't send multiple objects

Here is my controller code:

for(var i=0; i< $scope.files.length; i++){
  var bucket = new AWS.S3({ params: { Bucket: $scope.creds.bucket } });
  console.log($scope.files[i]);
  var file = $scope.files[i];
  var file_type = file.type.split("/")[1];
  var _uuid = uuid.new();
  var key = _uuid + "." + file_type;
  console.log("I: " + i);
  console.log("KEY: " + key);

  var params = { Key: key,
                 ContentType: file.type,
                 Body: file,
                 ServerSideEncryption: 'AES256' };

  bucket.putObject(params, function(err, data) {
    if(err) {
      // There Was An Error With Your S3 Config
      console.log(err);
      return false;
    }
    else {
      // Success!
      console.log("Temp Bucket Upload Done");
      $scope.uploaded.push(key);
      $scope.server_upl();
    }
  })
  .on('httpUploadProgress',function(progress) {
    // Log Progress Information
    //console.log(Math.round(progress.loaded / progress.total * 100) + '% done');
  });
}

Here for every file I'm creating a uuid. But if I browse for multiple files(n), somehow(?), for loops for n times and $scope.uploaded has n entities but all the entities has same uuid. What is the thing that I don't see here?




Aucun commentaire:

Enregistrer un commentaire