title: AWS getObject retrieve metadata (filename)
body: <p>I'm unable to get the object's metadata, always getting undefined as a result. This is the code snippet:</p>
  
  <pre><code>.then(function(answer) {
      if (answer === "publish") {
          //zip files here
          var zip = new JSZip();
          //var folder = zip.folder($scope.createYear + "/" + $scope.createMonth + "/" + $scope.JiraNo);
          var folder = zip.folder("ISE/" + $scope.JiraNo);
          //var imageFolder = zip.folder($scope.createYear + "/" + $scope.createMonth + "/" + $scope.JiraNo + "/img");
          var imageFolder = zip.folder("ISE/" + $scope.JiraNo + "/img");
  
          // Configure The S3 Object
          AWS.config.update({
              accessKeyId: $scope.creds.access_key,
              secretAccessKey: $scope.creds.secret_key
          });
          AWS.config.region = "ap-southeast-2";
  
          var bucket = new AWS.S3({
              params: {
                  Bucket: $scope.creds.bucket,
                  Prefix: $scope.creds.path + "/" + $scope.createYear + "/" + $scope.AddLeadingZeroToMonth($scope.createMonth) + "/" + $scope.JiraNo + "/img/"
              }
          });
  
          var listObjectPromise = bucket.listObjects(bucket.params).promise();
          listObjectPromise.then(function(data) {
              var promises = [];
              // download image files into an array of 64 bit encoded files
              for (var i = 0; i &lt; data.Contents.length; i++) {
                  var params = {
                      Bucket: $scope.creds.bucket,
                      Key: data.Contents[i].Key
                  }
                  var getObjectPromise = bucket.getObject(params).promise();
                  promises.push(getObjectPromise);
                  getObjectPromise.then(function(data) {
                      console.log("Loaded filename: ", data.Metadata);
                      imageFolder.file("image.png", data.Body);
                  }).catch(function(error) {
                      console.log("Failed to retrieve an object: " + error);
                  });
              }
  
              $q.all(promises).then(function(data) {
                  console.log("&gt;&gt;&gt;&gt;&gt;&gt; All promises are resolved, zipping file &gt;&gt;&gt;&gt;&gt;&gt;");
                  folder.file("campaign.json", JSON.stringify(JSONdata));
  
                  if (CSSdata) {
                      UPLOADdataSize++;
                      CSSdata = CSSdata.replace(new RegExp("&lt;div&gt;", "g"), "");
                      CSSdata = CSSdata.replace(new RegExp("&lt;/div&gt;", "g"), "");
                      CSSdata = CSSdata.replace(new RegExp("&lt;br&gt;", "g"), "");
                      CSSdata = CSSdata.replace(new RegExp("&amp;nbsp;", "g"), "");
                      folder.file("style.scss", CSSdata);
                  }
  
                  if (JSdata) {
                      UPLOADdataSize++;
                      JSdata = JSdata.replace(new RegExp("&lt;div&gt;", "g"), "");
                      JSdata = JSdata.replace(new RegExp("&lt;/div&gt;", "g"), "");
                      JSdata = JSdata.replace(new RegExp("&lt;br&gt;", "g"), "");
                      JSdata = JSdata.replace(new RegExp("&amp;nbsp;", "g"), "");
                      folder.file("script.js", JSdata);
                  }
  
                  zip.generateAsync({
                          type: "blob"
                      })
                      .then(function(content) {
                          saveAs(content, $scope.JiraNo + ".zip");
                      });
              });
          }).catch(function(error) {
              console.log("S3 listing error: ", error);
          });
      }
  }, function() {});
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/O9MV1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O9MV1.png" alt="enter image description here"></a></p>
  
  <p>This is the response I get in the browser for Metadata object</p>
  
  <p>Can someone please help how to retrieve a value from an object like that. Thank you.</p>