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
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.4.16
zachdaniel
Correct on the admin question, but not yet, but we would like to implement that ![]()
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
It would be a welcome addition
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.







