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.
Apache License 2.0
827 stars 278 forks source link

Can't support AWS China Region url. #77

Open dkstsh opened 4 years ago

dkstsh commented 4 years ago

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.

dkstsh commented 4 years ago

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;
    }
}
MattBlissett commented 3 years ago

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:

https://github.com/awslabs/aws-js-s3-explorer/blob/4de1fd016f098eec491605829530c31387870b63/index.html#L688-L690

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).