简体   繁体   中英

Access file from one folder of a bucket to another folder of the same bucket in AWS S3

I have an Amazon S3 bucket. Inside the bucket are two folders:

  • In the first folder there is an index.html file
  • In the second bucket there is a .js file

How do I access the .js file in the second bucket from the index.html file in first bucket?

index.html

<html>
 <head>
    <script type="text/javascript" src="/folder2/array.js"></script>
 </head>
 <body>
    <input type="button" onclick="go()" value="Display JS Array"/>
    <script>
        go();
    </script>
 </body>
</html>

array.js

`function go(){
 var array = new Array();
 array[0] = "Red";
 array[1] = "Blue";
 array[3] = "Green";
 for (var i=0; i < array.length; i++){
    document.write("<li>" + array[i] + "<br />");
 }
}`

You could use the full path to the file.

For example, if your bucket is called bucket-name-2 and is in the Sydney region, the link to the .js file would be:

https://s3-ap-southeast-2.amazonaws.com/bucket-name-2/array.js

(These URLs are displayed in the Amazon S3 management console.)

If both buckets are in the same region, you could probably refer to the file via:

src=/bucket-name-2/array.js

This is because they would share the same DNS name, but would vary on the bucket name.

If you have activated static website hosting , the URL would look like:

http://my-bucket.s3-website-ap-southeast-2.amazonaws.com/array.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM