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

3

18

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?

Stabilize answered 5/5, 2011 at 12:17 Comment(0)
B
9

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.

Barbusse answered 12/6, 2011 at 13:46 Comment(4)
doesnt seem to work. both.get empty page, despite all files public and not running as website bucket.Corbett
@devdude, can you turn on Javascript debugging to see if the script is failing anywhere?Barbusse
Firebug: response is null handleList()list.html (line 104) [Break On This Error] filex = response.getElementsByTagName('Contents');Corbett
Didn't worked for me neither, Rufus Pollock's solution worked wellAppassionato
S
7

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

Skellum answered 11/5, 2013 at 13:35 Comment(0)
G
0

you should use the Amazon S3 API to list the buckets and files within them
a bucket can represent a folder (will be easier than using prefix's on the file name)

after creating your buckets and uploading the files to them
you can present the buckets on a page with a List All My Buckets request
once a user clicks on a given bucket you can get the files in it using a List Bucket request
another last click on the file to generate a url for the object so the user can download it without wasting your bandwidth

you can find many implementations to the amazon s3 api here

Ganda answered 5/5, 2011 at 12:43 Comment(1)
Are these APIs callable from Javascript? Any samples? otherwise I'm not sure how I'd use them from within a browser. I was hoping for something I could serve up from within the S3 space.Stabilize

© 2022 - 2024 — McMap. All rights reserved.