awslabs / aws-js-s3-explorer

AWS JavaScript S3 Explorer is a JavaScript application that uses AWS's JavaScript SDK and S3 APIs to make the contents of an S3 bucket easy to browse via a web browser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't support AWS China Region url.

dkstsh opened this issue · comments

When click the object in the explorer list, the open window was blank with wrong url format, like "bucketname.s3-cn-north-1.amazonaws.com/object". Maybe cause by AWS china region url format is different with global region. The object correct url format is "bucketname.s3.cn-north-1.amazonaws.com.cn/object".

Please fix it, Thanks.

fix it:
function object2hrefvirt(bucket, key) {
var enckey = key.split('/').map(function (x) {
return encodeURIComponent(x);
}).join('/');

    if (AWS.config.region === "us-east-1") {
        return document.location.protocol + '//' + bucket + '.s3.amazonaws.com/' + enckey;
    } 

** fix this else if (AWS.config.region === "cn-north-1") {
return document.location.protocol + '//' + bucket + '.s3.' + AWS.config.region + '.amazonaws.com.cn/' + enckey;
**

    } else {
        return document.location.protocol + '//' + bucket + '.s3-' + AWS.config.region + '.amazonaws.com/' + enckey;
    }
}

I noticed the same issue with the af-south-1 region. This fix seems to work.

I'll copy the change above, since the formatting is broken. s3- is changed to s3.

    function object2hrefvirt(bucket, key) {
        var enckey = key.split('/').map(function(x) { return encodeURIComponent(x); }).join('/');

        if (AWS.config.region === "us-east-1") {
            return document.location.protocol + '//' + bucket + '.s3.amazonaws.com/' + enckey;
        } else {
            return document.location.protocol + '//' + bucket + '.s3.' + AWS.config.region + '.amazonaws.com/' + enckey;
        }
    }

    function object2hrefpath(bucket, key) {
        var enckey = key.split('/').map(function(x) { return encodeURIComponent(x); }).join('/');

        if (AWS.config.region === "us-east-1") {
            return document.location.protocol + "//s3.amazonaws.com/" + bucket + "/" + enckey;
        } else {
            return document.location.protocol + "//s3.' + AWS.config.region + '.amazonaws.com/" + bucket + "/" + enckey;
        }
    }

I would submit a PR, but I spotted this:

// The following is also a legal form, but we do not support it, so
// you should use s3-eu-central-1 rather than s3.eu-central-1:
// - bucket3.s3.eu-central-1.amazonaws.com

and I don't know enough about AWS URLs to be sure of all the possibilities. s3-eu-central-1 works, but s3-af-south-1 does not.

(The URLs don't seem to be consistent between regions, e.g. https://gbif-open-data-eu-central-1.s3-eu-central-1.amazonaws.com/occurrence/2021-04-13/citation.txt and https://gbif-open-data-eu-central-1.s3.eu-central-1.amazonaws.com/occurrence/2021-04-13/citation.txt both work, with either s3-eu-central-1 or s3.eu-central-1, but https://gbif-open-data-af-south-1.s3-af-south-1.amazonaws.com/occurrence/2021-04-13/citation.txt doesn't work; https://gbif-open-data-af-south-1.s3.af-south-1.amazonaws.com/occurrence/2021-04-13/citation.txt does).