MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / viewAlbum

Function viewAlbum

javascript/example_code/s3/s3_photoExample.js:95–149  ·  view source on GitHub ↗
(albumName)

Source from the content-addressed store, hash-verified

93
94// snippet-start:[s3.JavaScript.photoAlbumExample.viewAlbum]
95function viewAlbum(albumName) {
96 var albumPhotosKey = encodeURIComponent(albumName) + "/";
97 s3.listObjects({ Prefix: albumPhotosKey }, function (err, data) {
98 if (err) {
99 return alert("There was an error viewing your album: " + err.message);
100 }
101 // 'this' references the AWS.Response instance that represents the response
102 var href = this.request.httpRequest.endpoint.href;
103 var bucketUrl = href + albumBucketName + "/";
104
105 var photos = data.Contents.map(function (photo) {
106 var photoKey = photo.Key;
107 var photoUrl = bucketUrl + encodeURIComponent(photoKey);
108 return getHtml([
109 "<span>",
110 "<div>",
111 '<img style="width:128px;height:128px;" src="' + photoUrl + '"/>',
112 "</div>",
113 "<div>",
114 "<span onclick=\"deletePhoto('" +
115 albumName +
116 "','" +
117 photoKey +
118 "')\">",
119 "X",
120 "</span>",
121 "<span>",
122 photoKey.replace(albumPhotosKey, ""),
123 "</span>",
124 "</div>",
125 "</span>",
126 ]);
127 });
128 var message = photos.length
129 ? "<p>Click on the X to delete the photo</p>"
130 : "<p>You do not have any photos in this album. Please add photos.</p>";
131 var htmlTemplate = [
132 "<h2>",
133 "Album: " + albumName,
134 "</h2>",
135 message,
136 "<div>",
137 getHtml(photos),
138 "</div>",
139 '<input id="photoupload" type="file" accept="image/*">',
140 '<button id="addphoto" onclick="addPhoto(\'' + albumName + "')\">",
141 "Add Photo",
142 "</button>",
143 '<button onclick="listAlbums()">',
144 "Back To Albums",
145 "</button>",
146 ];
147 document.getElementById("app").innerHTML = getHtml(htmlTemplate);
148 });
149}
150// snippet-end:[s3.JavaScript.photoAlbumExample.viewAlbum]
151
152// snippet-start:[s3.JavaScript.photoAlbumExample.addPhoto]

Callers 3

createAlbumFunction · 0.70
addPhotoFunction · 0.70
deletePhotoFunction · 0.70

Calls 1

getHtmlFunction · 0.85

Tested by

no test coverage detected