Created
November 19, 2014 10:41
-
-
Save mfellner/8f02128f2d84640292b2 to your computer and use it in GitHub Desktop.
AWS S3 Index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
</head> | |
<body> | |
<table id="table"> | |
<tbody> | |
<tr> | |
<td>Name</td> | |
<td>Size</td> | |
<td>Last Modified</td> | |
</tr> | |
</tbody> | |
</table> | |
<script src="//sdk.amazonaws.com/js/aws-sdk-2.0.0-rc13.min.js"></script> | |
<script type="text/javascript"> | |
(function () { | |
'use strict'; | |
var s3 = new AWS.S3(); | |
s3.makeUnauthenticatedRequest('listObjects', { | |
Bucket: 'your-bucket-name', | |
Delimiter: '/' | |
}, function (err, data) { | |
if (err) { | |
console.log(err, err.stack); | |
} | |
else { | |
makeListing(data); | |
} | |
}); | |
function makeListing(data) { | |
if (data.Contents) { | |
data.Contents.forEach(function (obj) { | |
addTableRow('table', | |
'<td>' + obj.Key + '</td>' + | |
'<td>' + obj.Size + '</td>' + | |
'<td>' + obj.LastModified + '</td>'); | |
}); | |
} | |
if (data.CommonPrefixes) { | |
data.CommonPrefixes.forEach(function (obj) { | |
addTableRow('table', | |
'<td><a href="' + obj.Prefix + '">' + obj.Prefix + '</a></td>' + | |
'<td></td>' + | |
'<td></td>'); | |
}); | |
} | |
} | |
function addTableRow(table, content) { | |
var tr = document.createElement('tr'); | |
tr.innerHTML = content; | |
document.getElementById(table).appendChild(tr); | |
} | |
}()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage