Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I provide directory listings for those viewing my Amazon S3 based static website?

I have an Amazon S3 account where I would like to store several directories of files.

I would like a visitor to this site to be able to see and download the files and folders I have placed there.

These files and folders will change regularly and I would prefer not to have to rewrite any html each time I added or removed files.

How can I arrange for the viewers of my site to be presented with a simple list of files/ folders?

like image 812
Rory Becker Avatar asked May 05 '11 12:05

Rory Becker


People also ask

Does AWS S3 have directories?

Directories don't actually exist within S3 buckets. The entire file structure is actually just one flat single-level container of files. The illusion of directories are actually created based on naming the files names like dirA/dirB/file .

Can you upload a directory to S3?

To upload folders and files to an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.


2 Answers

You can use Javascript to list the files.

Here is the solution provided by Amazon:

http://aws.amazon.com/code/Amazon-S3/1713

You place list.html in every directory you want to list.

I have made my own listing file that provides a collapsible tree view:

https://github.com/phatmann/jS3Tree/blob/master/index.html

Neither of these files will work if you are using the S3 website feature.

like image 124
phatmann Avatar answered Nov 26 '22 06:11

phatmann


I've created a simple bit of JS that creates a directory index in HTML style that would fit what you are looking for: https://github.com/rgrp/s3-bucket-listing

You can install this either directly into your s3 bucket or into a separate website (thanks to the fact that the S3 REST API supports CORS!). The README has full instructions on this: https://github.com/rgrp/s3-bucket-listing

like image 38
Rufus Pollock Avatar answered Nov 26 '22 06:11

Rufus Pollock