| 65 | |
| 66 | // snippet-start:[s3.JavaScript.photoAlbumExample.createAlbum] |
| 67 | function createAlbum(albumName) { |
| 68 | albumName = albumName.trim(); |
| 69 | if (!albumName) { |
| 70 | return alert("Album names must contain at least one non-space character."); |
| 71 | } |
| 72 | if (albumName.indexOf("/") !== -1) { |
| 73 | return alert("Album names cannot contain slashes."); |
| 74 | } |
| 75 | var albumKey = encodeURIComponent(albumName); |
| 76 | s3.headObject({ Key: albumKey }, function (err, data) { |
| 77 | if (!err) { |
| 78 | return alert("Album already exists."); |
| 79 | } |
| 80 | if (err.code !== "NotFound") { |
| 81 | return alert("There was an error creating your album: " + err.message); |
| 82 | } |
| 83 | s3.putObject({ Key: albumKey }, function (err, data) { |
| 84 | if (err) { |
| 85 | return alert("There was an error creating your album: " + err.message); |
| 86 | } |
| 87 | alert("Successfully created album."); |
| 88 | viewAlbum(albumName); |
| 89 | }); |
| 90 | }); |
| 91 | } |
| 92 | // snippet-end:[s3.JavaScript.photoAlbumExample.createAlbum] |
| 93 | |
| 94 | // snippet-start:[s3.JavaScript.photoAlbumExample.viewAlbum] |