Giter VIP home page Giter VIP logo

s3album's Introduction

S3 Album Publisher

A pure client-side photo album publisher for S3.

Try it out here with your own S3 bucket, or view a demo of a published album.

Overview

  • Browse your bucket for photos.
  • Publish albums from your photos.
  • Share albums with their public URL.

The albums you publish are private: they can only be found if you know the album's URL.

Being a pure web-app means:

  • Configuration-free: upload the scripts to S3 and start publishing albums right away.
  • Database-free: no database is required for creating or viewing albums. Albums are self contained and portable.
  • No server-side scripts: all the operations are done in your browser, including resizing photos and thumbnails.

Getting Started

  1. Upload view.html, publish.html and publish.js to a path in your S3 bucket, for example, public-albums/. This can be done with s3cmd:
s3cmd put view.html publish.html publish.js s3://bucket/public-albums/
  1. In your browser, navigate to https://s3.region.amazonaws.com/bucket/public-albums/publish.html, enter your S3 credentials, and start publishing albums!

    For example, https://s3.sa-east-1.amazonaws.com/www.mycooldomain.com.br/public-albums/publish.html

    Since you're sending your AWS credentials, use HTTPS.

  2. CloudFront and FQDN doesn't work - you need to make use of the S3 API endpoint all the time.

How It Works

Publishing

publish.html uses the Amazon JavaScript SDK to browse your bucket for photos you would like to publish in an album. When you create a new album, a directory in your published albums path is created. For example, the album with name 'My Holiday Pics' is created in public-albums/albums/My Holiday Pics/. When you add a photo to the album:

  • it is copied, resized, and placed in public-albums/albums/My Holiday Pics/photos/; and
  • a thumbnail is created and placed in public-albums/albums/My Holiday Pics/thumbs/.

That's all there is to publishing. No databases. No calls to server-side scripts. No adding filenames to index files.

Viewing

view.html is used to view published albums. The name of the album is specified in the hash of the URL, for example, https://s3.region.amazonaws.com/bucket/public-albums/view.html#My%20Holiday%20Pics. The photos for the album are found by listing the contents of albums/My Holiday Pics/photos/ (relative to the location of view.html) and then dynamically added to the page.

S3 Bucket Policy

Anonymous access

If you want anyone on the web to view your published albums, your bucket policy should allow anonymous getObject and listBucket requests. If your bucket doesn't already allow anonymous requests, the mimimum you need to add is:

  • A statement allowing aonymous getObject requests to the path of your published albums, for example public-albums/:
{
  "Sid": "AnonGetAlbumObjects",
  "Effect": "Allow",
  "Principal": "*",
  "Action": "s3:GetObject",
  "Resource": [
    "arn:aws:s3:::bucket/public-albums/*",
    "arn:aws:s3:::bucket/favicon.ico"
  ]
},
  • A statement allowing anyone to list the contents of the individual album directories (but not list all the albums that you have):
{
  "Sid": "AnonListObjects",
  "Effect": "Allow",
  "Principal": "*",
  "Action": "s3:ListBucket",
  "Resource": "arn:aws:s3:::bucket",
  "Condition": {
    "StringLike": {
      "s3:prefix": "public-albums/albums/*/"
    }
  }
},

S3 user

The S3 user (also called principal) that you use to publish the albums should have permission to:

  • read and list the paths where the original photos are stored; and
  • read, list and write the path where the albums are published to, again, for example, public-albums/.

If your user has all permisions on the whole bucket, then no changes to the bucket policy are necessary. However, if you want to restrict your user to the minimum permisions necessary, add the following statements:

  • Grant permission to read (but not write) the paths where the original photos are stored:
{
  "Sid": "ReadMyPhotosDir",
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::1234567890:user/my_albums_user"
  },
  "Action": "s3:GetObject",
  "Resource": "arn:aws:s3:::bucket/my/photo/collection/*"
}
  • Permission to list the paths where the original photos are stored, as well as the published albums:
{
  "Sid": "OnlyListSomeDirs",
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::1234567890:user/my_albums_user"
  },
  "Action": "s3:ListBucket",
  "Resource": "arn:aws:s3:::bucket",
  "Condition": {
    "StringLike": {
      "s3:prefix": [
        "my/photo/collection/*",
      "public-albums/*"
      ]
    }
  }
},
  • Finally, the user should have full control over the directory where the published albums are stored:
{
  "Sid": "ObjectActionsOnAlbumsDir",
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::1234567890:user/my_albums_user"
  },
  "Action": "s3:*",
  "Resource": [
    "arn:aws:s3:::bucket/public-albums/*",
  "arn:aws:s3:::bucket/public-albums"
  ]
},

Custom install

It is also possible to store the albums in your bucket, but keep the view.html on another website. To do this, you can edit the configuration in view.html to point to your S3 bucket. Also, you will need to ensure the CORS configuration for your bucket allows requests from different origins:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>HEAD</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <ExposeHeader>ETag</ExposeHeader>
    <ExposeHeader>x-amz-meta-custom-header</ExposeHeader>
    <AllowedHeader>*</AllowedHeader>
  </CORSRule>
</CORSConfiguration>

Dependencies

The following dependencies are included in the HTML files and hosted by CDNs (cdnjs and Goolge Hosted Libraries):

  • Bootstrap
  • jQuery
  • Fancybox
  • Amazon JavaScript SDK

Optional: External Image Resizer

By default, image resizing is done in the browser. This means that the original image is downloaded from S3, resized and then uploaded to its final location. This may perform badly with large photos, slow internet connections and/or slow web browsers. Furthermore, the resizing in the browser isn't perfect and may introduce artifacts.

There is a hook in publish.js to plugin your own image resizer. You can, for example, send a XHR request to a PHP script that will download, resize and upload the photo/thumb to the bucket.

TODO / Contributing

(Here's where you come in)

  • Automatically detect settings (bucket name, paths, etc.)
  • Support regions other than us-east-1
  • Choose photo and thumb sizes in settings dialog
  • Resize images in the browser without introducing artifacts.
  • Upload images directly from publish.html
  • Generate thumbnails for the bucket file browser
  • Select multiple files to add at the same time
  • Filter selectable file types
  • Make the general design more pretty

s3album's People

Contributors

aljazerzen avatar dcgomesbr avatar htelsiz avatar toehio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

s3album's Issues

Error specifying region

Thank you for this great tool. When I enter my preferences into publish.html and submit it says I'm using the wrong region. My bucket is in 'us-west-2' region. How would I specify the region? I see some default variables in publish.html. Is that the right place?

Regards,
Gil.

Editing album.html (view.html) for Cloudfront usage

When an album is published, I'd like to edit view.html to view the album using the CNAME assigned to the Cloudfront version of the bucket. A simple example or guidelines for editing would be appreciated.

Using the scripts to locally generate and upload albums

This is not necessarily an issue, but I didn't know where else to ask. Can you explain how these scripts work? Also, do you think it'd be feasible to develop something similar, but in Python?

I'd like to build a small-ish Python utility to loop over large sets of photos and make the contents of each directory an album. I think I'll start with boto3, although I haven't used the AWS SDK for years.

Let me know what you think. If I end up making a tool, I'd love to add it to this repo.

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256

Getting an error using publish.js. The response from Amazon says "The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256".

A stackoverflow post suggests using the following config:

AWS.config.update({
    signatureVersion: 'v4'
});

I just want to be able to make my own albums. Also, if you're still working on this, I'd love to start contributing.

consulting?

Are you available for consulting? I'd like to use this code but I need some help getting it running and I'd like some enhancements.

Thank you.

--kyler

Gallery is empty

Nice project, but how does "Gallery" work? I don't know how to add an album to a gallery. There's no option for that when creating a new album. What's the location of gallery in the bucket? Is anything more that needs to be configured in the bucket policy?

Can I not resize and copy the images?

I want to save storage space and see the images in their full size version (so I can download the full quality image) (other then thumbnails.

Is there any way, I can populate the album folder myself by uploading the images directly there?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.