AWS getObject检索元数据(文件名)

时间:2016-11-17 01:05:01

标签: node.js amazon-web-services amazon-s3 aws-sdk

我无法获取对象的元数据,因此总是未定义。这是代码段:

.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() {});

enter image description here

这是我在浏览器中获取的元数据对象的响应

有人可以帮助如何从像这样的对象中检索值。谢谢。

0 个答案:

没有答案