如何为nodejs中的每个桶生成Url

时间:2016-11-03 12:43:45

标签: node.js sails.js aws-sdk

我正在尝试为循环中的每个桶生成url,即迭代桶生成url并放入一个数组。请建议我最好的方法。

这是我正在尝试的代码..

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                        .setContentTitle(title)
                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(message))
                        .setContentText(message)
                        .setTicker("app_name")
                        .setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.drawable.icon_name)
                        .setLargeIcon(largeIcon)
                        .setColor(getBaseContext().getResources().getColor(R.color.green));
                                ....
                        Notification notification = mBuilder.build();

**int smallIconId = getResources().getIdentifier("icon_name", "drawable" , getApplicationContext().getPackageName());
notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);**

1 个答案:

答案 0 :(得分:0)

我是这样做的(我已经从aws-sdk宣传了S3,这段代码来自我的项目,所以你可能需要稍微更改一下代码):

return Bluebird.try(function () {    
        const params = {
            Bucket: <BUKCET>, /* required */
            // ContinuationToken: '',
            Prefix: <PREFIX>,  //optional
            StartAfter: <STARTAFTER>  //optional
        };

        // Prefix is for filtering your objects if say you store objects like userID/message1 so prefix can be userID

        // List all objects, for Keys for which we will create URLs
        return AWS.S3.listObjectsV2Async(params);
    }).then(function (data) {
        console.log("ALL OBJECTS FOR REQUEST: ", data.Contents);

        const createSignedUrlPromises = [];
        const response = [];

        const message_ids = [];


        // For each object, create a promise for making signed url
        _.forEach(data.Contents, function (content) {
            const params = {
                Bucket: <BUCKET>,
                Key: content.Key,
                Expires: <EXPIRY>
            };   
            createSignedUrlPromises.push(AWS.S3.getSignedUrlAsync('getObject', params));
        });


        return Bluebird.all(createSignedUrlPromises).then(function (data) {
            console.log("URLS FOR VOICE MESSAGES: ", data);


            // data is an array of signed urls for all objects in your bucket
        });
    });