/** * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * http://aws.amazon.com/apache2.0/ * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * */ // snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.] // snippet-sourcedescription:[s3_PhotoViewer.js demonstrates how to allow viewing of photos in albums stored in an Amazon S3 bucket.] // snippet-service:[s3] // snippet-keyword:[JavaScript] // snippet-keyword:[Amazon S3] // snippet-keyword:[Code Sample] // snippet-sourcetype:[full-example] // snippet-sourcedate:[2019-05-07] // snippet-sourceauthor:[AWS-JSDG] // ABOUT THIS JAVASCRIPT SAMPLE: This sample is part of the SDK for JavaScript Developer Guide topic at // https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photos-view.html // snippet-start:[s3.JavaScript.s3_PhotoViewer.complete] // // Data constructs and initialization. // // snippet-start:[s3.JavaScript.s3_PhotoViewer.config] // **DO THIS**: // Replace BUCKET_NAME with the "PhotoBucket" output value from the CloudFormation stack. // var albumBucketName = 'photo-albums-eu-west-1-104552851521'; // Create a new service object var s3 = null; // A utility function to create HTML. function getHtml(template) { return template.join('\n'); } // snippet-end:[s3.JavaScript.s3_PhotoViewer.config] // // Functions // // snippet-start:[s3.JavaScript.s3_PhotoViewer.listAlbums] // List the photo albums that exist in the bucket. function listAlbums() { s3.listObjects({Delimiter: '/'}, function(err, data) { if (err) { return alert('There was an error listing your albums: ' + err.message); } else { var albums = data.CommonPrefixes.map(function(commonPrefix) { var prefix = commonPrefix.Prefix; var albumName = decodeURIComponent(prefix.replace('/', '')); return getHtml([ '
Click on an album name to view it.
', ]) : 'You do not have any albums. Please Create album.'; var htmlTemplate = [ '
The following photos are present.
' : 'There are no photos in this album.
'; var htmlTemplate = [ '