How to config aws sdk js to use the getObject function through Spaces CDN?

May 9, 2019 372 views
CDN DigitalOcean Storage

I’m doing a Image Proxy Server and the problem is, some requests take a long time, more than 30s.

How I can improve it to get the objects more quickly?

Maybe the problem is because the requests are not going through the CDN.

My aws sdk js config is:

    accessKeyId: '',
    secretAccessKey: '',
    bucket: 'bucketname',
    endPoint: 'ams3.digitaloceanspaces.com',
    region: 'ams3'

and this function to get the object from Spaces:

    getFile: function(res, file) {
        return new Promise((resolve, reject) => {
            s3.getObject({ Bucket: 'bucketname', Key: file }, (err, data) => {
                //console.log(res, err, data);
                if (!err) {
                    return resolve(data);
                } else {
                    return reject(err, res);
                }
            });
        }).catch((err) => {
            console.log('Error:', err.statusCode);
        });
    },
Be the first one to answer this question.