{"id":13508815,"url":"https://github.com/gjaldon/ectophile","last_synced_at":"2025-03-16T07:32:18.646Z","repository":{"id":57493516,"uuid":"42326557","full_name":"gjaldon/ectophile","owner":"gjaldon","description":"Ectophile is an extension for Ecto models to instantly support file uploads.","archived":false,"fork":false,"pushed_at":"2016-02-07T13:34:10.000Z","size":34,"stargazers_count":42,"open_issues_count":5,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-08T14:04:05.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gjaldon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-11T18:52:11.000Z","updated_at":"2023-09-01T11:28:36.000Z","dependencies_parsed_at":"2022-08-28T13:53:32.932Z","dependency_job_id":null,"html_url":"https://github.com/gjaldon/ectophile","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjaldon%2Fectophile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjaldon%2Fectophile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjaldon%2Fectophile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gjaldon%2Fectophile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gjaldon","download_url":"https://codeload.github.com/gjaldon/ectophile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806046,"owners_count":20350775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:58.855Z","updated_at":"2025-03-16T07:32:18.225Z","avatar_url":"https://github.com/gjaldon.png","language":"Elixir","funding_links":[],"categories":["ORM and Datamapping"],"sub_categories":[],"readme":"Ectophile\n========\n\nEctophile is an extension for Ecto models to instantly support file uploads.\n\n## Usage\n\n`Ectophile` provides an `attachment_fields/2` macro for your model which is used like:\n\n```elixir\ndefmodule MyApp.User do\n  use Ectophile  #=\u003e Note that this needs to be used before MyApp.Web so that the callbacks will work\n  use MyApp.Web, :model\n\n  schema \"users\" do\n    field :email, :string\n\n    attachment_fields :avatar\n    timestamps\n  end\n\n  ...\nend\n```\n\n`attachment_fields/2` in the above example, defines two different fields which are:\n\n  - `field :avatar, Ectophile.Type`\n  - `field :avatar_upload, :any, virtual: true`\n\nThe `:avatar` field is where the path to the file in your filesystem and filename is saved. `:avatar_upload` is the field we'll use for file uploads.\n\nKeep in mind that you will need to create the necessary `migration` to add the `Ectophile` fields to your model like so:\n\n```elixir\ndefmodule SampleMigration do\n  use Ecto.Migration\n\n  def change do\n    create table(:users) do\n      add :email\n      add :avatar, :jsonb #=\u003e The column we need for Ectophile's custom field\n      timestamps\n    end\n  end\nend\n```\n\nAlso, set the `:otp_app` in your config like:\n\n```elixir\n# config/config.exs\nuse Mix.Config\n\nconfig :ectophile, otp_app: :yourapp\n```\n\nIn your application's top-level supervisor's `start/2` function, add the following to setup the directories where your files will be uploaded:\n\n```elixir\nimport Ectophile.Helpers\n\ndef start(_type, _args) do\n  ensure_upload_paths_exist([MyApp.User]) #=\u003e This creates all the required directories for your uploaded files\n  ...\nend\n```\n\nAfter doing the migrations and defining your model's `attachment_fields`, you can then add file upload field to your model's form like:\n\n```html\n...\n\n\u003cdiv class=\"form-group\"\u003e\n  \u003c%= label f, :avatar_upload, \"Avatar\" %\u003e\n  \u003c%= file_input f, :avatar_upload, class: \"form-control\" %\u003e\n\u003c/div\u003e\n\n...\n```\n\nThat's it!!! Now every time a user uploads a file and submits a form, that file is stored in a configurable location in your `priv/static` directory and a reference to that file is stored in your database.\n\nIn your template, you can then do:\n\n```html\n\u003cimg alt=\"\u003c%= @user.avatar %\u003e\" src=\"\u003c%= static_path(@conn, Ectophile.Helpers.static_path(avatar)) %\u003e\"\u003e\n```\n\n## Important links\n\n  * Documentation - to be published\n  * [License](https://github.com/gjaldon/ectophile/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgjaldon%2Fectophile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgjaldon%2Fectophile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgjaldon%2Fectophile/lists"}