S3 custom provider -> Add region field and make code a bit more custom provider friendly

Pretty sure this fell under the cracks.

I finally found some time to undo all my custom code in the core files thanks to the past inclusion of dotenv and redis.

This is just the one thing that keeps me discarding changes in GIT with every Wappler update.

setS3Provider: function(name, options) {
        options = this.parse(options);
        
        const AWS = require('aws-sdk');
        const endpoint = new AWS.Endpoint(this.parseRequired(options.endpoint, 'string', 's3.provider: endpoint is required.'));
        const accessKeyId = this.parseRequired(options.accessKeyId, 'string', 's3.provider: accessKeyId is required.');
        const secretAccessKey = this.parseRequired(options.secretAccessKey, 'string', 's3.provider: secretAccessKey is required.');

        let region = 'fr-par';
        let pos = options.endpoint.indexOf('.amazonaws');
        if (pos > 3) region = options.endpoint.substr(3, pos - 3);

        this.s3[name] = new AWS.S3({ endpoint, accessKeyId, secretAccessKey, region, signatureVersion: 'v4' });

        return this.s3[name];
    },

Could you guys add something of the sorts and the field in the UI?

let region = options.region || 'us-east-1';

I still need to manually change it to fr-par every time.

1 Like