Mallery is a simple image gallery that can be populated by sending emails with image attachments.
The email subject will be used as a description for the attached images. The email attachment filename will be used as name.
All images will be resized to 400x300 to show thumbnails in the gallery. This thumbnail links to the original variant.
Some needed environment variables before starting:
- CLOUD_IO_TOKEN: Token for cloudimage.io
- AWS_ACCESS_KEY_ID: Key id for aws (used for s3)
- AWS_SECRET_ACCESS_KEY: Access key for aws (used for s3)
This part has only been tested with mailgun. You need to forward emails to the /mailgun endpoint. Emails without any image attachments will not be processed.
If you'd like mailgun to only forward messages that have attachments you can use
the following filter rule: match_header("Content-Type", "^multipart/mixed(.*)$")
The /mailgun endpoint offers each image attachment as a separate work item. When all of the items have been uploaded (only S3 supported) the request is considered done. All images will go to the same bucket at the moment.
After successful uploads, each url for the images are then saved to db. cloudimage.io is used to resize the images into suitable thumbnails when a gallery is requested.
Everything that is persited can be viewed (and edited) on the /images
html endpoint. Disable it for production.
- Global html gallery that shows all images:
/gallery/
- To view a user's html gallery go to
/gallery/<user>
, where user = email address. - JSON API:
- GET:
/api/gallery
,/api/gallery/<user>
- GET/DELTE/PUT:
/api/image/<id>
- GET:
Starting an "incoming image attachment" job from iex:
Mallery.Work.S3Upload.call(:image_pool, {:process, [%Mallery.Work.Item{file: "/path/to/my/file.png", id: "somerandomid", name: "file.png", content_type: "image/png", description: "Hello"}]})
Sending an email with attachment via mailgun:
curl -s --user 'my:apikey' \
https://api.mailgun.net/v3/mysandbox.mailgun.org/messages \
-F from='Foo <foo@mysandbox.mailgun.org>' \
-F to='alice@mysandbox.mailgun.org' \
-F subject='Hello' \
-F text='Text' \
-F attachment=@/path/to/my/file.png
- Issue get requests for cloudimage.io urls as soon as possible (reduce wait time for first user access)
- Use channels to notify on new images and show them right away
To start your Mallery:
For development you can start a postgres instance with the included docker-compose file:
docker-compose up
After that edit config/dev.exs
and set the Mallery.Repo hostname to wherever docker is. Then go ahead and:
- Install dependencies with
mix deps.get
- Create and migrate your database with
mix ecto.create && mix ecto.migrate
- Start Phoenix endpoint with
mix phoenix.server
Now you can visit localhost:4000
from your browser.
Ready to run in production? Please check deployment guides.