Yxizzy
Hey, I am trying to upload an image to Elixir from a form and then to gcs using arc. The form returns an empty response from Elixir on submit. Whenever I upload an image, I get empty parameter from Elixir, please what can be the cause, why is Elixir receiving empty parameters. I am new to using Elixir and Arc, so I will like to confirm if my code is correct.
This is my mix.exs file
{:arc_gcs, "~> 0.1.0"},
{:arc_ecto, "~> 0.11.1"},
{:arc, "~> 0.11.0"}
Then my route for creating the post is
resources “/images”, ImagesController, except: [:new, :edit]
My Images Controller.create
def create(conn, images_params) do
images_params["id"]})
with {:ok, %Images{} = images} <- Images.create_images(images_params) do
conn
|> put_status(:created)
|> put_resp_header("location", images_path(conn, :show, images))
|> render("show.json", images: images)
end
end
This is my Images Model
schema "image" do
field :name, :string
field :image, Myapp.Avatar.Type
timestamps()
end
@doc false
def changeset(images, attrs) do
images
|> cast(attrs, [:name])
|> validate_required([:name])
|> put_name
|> cast_attachments(attrs, [:image])
end
def put_name(changeset) do
case changeset do
%Ecto.Changeset{
valid?: true,
changes: %{upload: %Plug.Upload{content_type: "image/" <> _, filename: name}}
} ->
put_change(changeset, :name, name)
_ ->
changeset
end
end
def store(%Plug.Upload{} = upload, image) do
Avatar.store({upload, image})
end
def url(image, version) do
Avatar.url({image.name, image}, version)
end
end
And finally my Arc Uploader
@versions [:original]
def __storage, do: Arc.Storage.GCS
def gcs_object_headers(:original, {file, _scope}) do
[content_type: MIME.from_path(file.file_name)]
end
#To add a thumbnail version:
@versions [:original, :thumb]
# Override the bucket on a per definition basis:
# def bucket do
# :custom_bucket_name
# end
# Whitelist file extensions:
def validate({file, _}) do
~w(.jpg .jpeg .gif .png) |> Enum.member?(Path.extname(file.file_name))
end
def transform(:thumb, _file) do
{:convert, "-thumbnail x#{@heights[:thumb]} -gravity center -format jpg"}
end
def transform(:show, _file) do
{:convert, "-strip -resize x#{@heights[:show]} -gravity center -format png"}
end
def storage_dir(version, {_, image}) do
"uploads/posts/images/#{image.id}/#{version}"
end
def filename(_version, {file, _}) do
Path.rootname(file.file_name)
end
end
This is expected to receive the uploaded image from the web and save it on Google Cloud Storage but the I'm still getting an empty parameter. I have been on this for days, any help at all would be really appreciated, please someone should look into this and tell me where I might be getting it wrong.
Thanks
Trending in Questions
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
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
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
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
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
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
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
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
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
Anything in the logs? What’s the EEX contents? Etc…
alvinncx
Did you pass
multipart: truein yourform_forfunction?