adrian

adrian

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!

Showing Posts 1 to 7

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

adrian

adrian OP

Thanks for your quick reply, @zachdaniel !

To be honest, I have no idea how I could do it :slight_smile:

I need to add the :file type as an attribute and another :string attribute to indicate the path or URL where I store the file?

Do you think it’s possible to use Wafle or any other upload library with custom storage options to manage the uploaded files in ash?

What would be the basic steps to implement the possibility to work with files?

I guess this is not integrated with ash_admin yet isn’t it?

Thanks for your help!

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
adrian

adrian OP

I realized a made a mistake in the title, I meant Json Api.

adrian

adrian OP

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

I am very new to Ash, but if you think it’s a good idea, I could try implementing it in the admin.

My main obstacle is unfamiliarity with the contributions workflow, and I probably need some guidance.

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.

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews