adrian

adrian

Storing and uploading files using the JSON API?

Hello,

I couldn’t find how to deal with files using ash in the docs.

I found the File Type but it’s not what I expect.

I want to be able to store the file on disk and save the path in the database.

In the future I want to upload files using the JSON API.

Thank you!

Most Liked

zachdaniel

zachdaniel

Creator of Ash

The :file type is primarily meant for accepting files over interfaces. You’d add a file as an argument, and then use a change on the action to take that file and do something with it. Like you can move it from the temporary directory it is uploaded to by default when it’s a plug.upload, etc.

Really need to write a more comprehensive guide on dealing with file uploads: AshJsonApi.Plug.Parser — ash_json_api v1.7.0

zachdaniel

zachdaniel

Creator of Ash

Correct on the admin question, but not yet, but we would like to implement that :slight_smile:

You can potentially use Waffle, although not something like WaffleEcto

create :create_user do
  argument :profile_photo, :file
  change fn changeset, _ ->
    Ash.Changeset.before_transaction(changeset, fn changeset, _ ->
      if upload = changeset.arguments[:file] do
         url = <upload to s3>
         Ash.Changeset.force_change_attribute(changeset, :profile_photo_url, url)
      else
         changeset
      end
    end
  end
end
zachdaniel

zachdaniel

Creator of Ash

It would be a welcome addition :slight_smile: I suspect that it will be surprisingly complex but I could be wrong. Ultimately the pattern would be to fork ash_admin and then submit a PR. Everything would be done in the form component when rendering attribute inputs.

Last Post!

artyom87

artyom87

Yeah, right. Images and files are definitely a big problem. Although images and files are an integral part of any web project. Fork ash_admin - is just not right. There is still a lack of taxonomy in the ash_admin data tables.

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement