Yxizzy

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

Showing Posts 1 to 2

OvermindDL1

OvermindDL1

Anything in the logs? What’s the EEX contents? Etc… :slight_smile:

alvinncx

alvinncx

Did you pass multipart: true in your form_for function?

— All posts loaded —

Where Next? Top

Trending in Questions Top

Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
mandar1045
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews