问题描述:

I'm unable to get the object's metadata, always getting undefined as a result. This is the code snippet:

.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 < 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(">>>>>> All promises are resolved, zipping file >>>>>>");

folder.file("campaign.json", JSON.stringify(JSONdata));

if (CSSdata) {

UPLOADdataSize++;

CSSdata = CSSdata.replace(new RegExp("<div>", "g"), "");

CSSdata = CSSdata.replace(new RegExp("</div>", "g"), "");

CSSdata = CSSdata.replace(new RegExp("<br>", "g"), "");

CSSdata = CSSdata.replace(new RegExp("&nbsp;", "g"), "");

folder.file("style.scss", CSSdata);

}

if (JSdata) {

UPLOADdataSize++;

JSdata = JSdata.replace(new RegExp("<div>", "g"), "");

JSdata = JSdata.replace(new RegExp("</div>", "g"), "");

JSdata = JSdata.replace(new RegExp("<br>", "g"), "");

JSdata = JSdata.replace(new RegExp("&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() {});

This is the response I get in the browser for Metadata object

Can someone please help how to retrieve a value from an object like that. Thank you.

相关阅读:
Top