Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple uploads example #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,52 @@ Both public and signed urls will include the timestamp for cache busting, and ar
MyApp.Avatar.url({user.avatar, user}, :thumb, signed: true)
```

### Example of multiple uploads

Multiple uploads through embedded schema.

```elixir

# Embeded schema
defmodule Photo do
use Ecto.Schema
use Arc.Ecto.Schema

import Ecto.Changeset

@primary_key false

embedded_schema do
field :fileinfo, Myapp.Uploader.Type
end

def changeset(photo, params \\ %{}) do
photo
|> cast(params, [])
|> cast_attachments(params, [:fileinfo], allow_paths: true)
end
end

# Database schema
defmodule Post do
embeds_many :photos, Photo, on_replace: :delete
end

# Controller
def update(conn, params) do
post = Repo.get! Post, params["id"]

photos = for f <- params["uploads"] do
%Photo{}
|> Photo.changeset(%{fileinfo: f})
end

Post.changeset(post)
|> Ecto.Changeset.put_embed(:photos, photos)
|> Repo.update
end
```

## License

Copyright 2015 Sean Stavropoulos
Expand Down