asnyder002

asnyder002

I have DropZone.js set up to accept an uploaded file.

  <div class="container">
  <%= form_for @conn, Routes.admin_upload_path(@conn, :create, []), [data: [turbolinks: false], multipart: true, class: " dropzone dz-clickable rounded-lg h-1/2  bg-gray-200 justify-center my-5 flex flex-wrap", id: "mydropzone", name: "mydropzone"], fn f-> %>
      <div class="dropzone-previews"></div>
    <% end %>
  </div>

Once uploaded, the file properly gets sent to the correct action:

  def create(conn, %{"upload" => upload} = params) do
    # Temp use for testing
    csv_sha256 = "1fa7cfa1068a21894ebdab8edfd074453571c0d5520223380d8c44c633b4e288"

    conn
    |> put_flash(:info, "file uploaded correctly")
    |> redirect(to: Routes.admin_upload_path(conn, :show, csv_sha256))
  end

  def show(conn, %{"csv_sha256" => csv_sha256} = params) do
    shipments = App.list_shipments_by_csv_sha256()
    render(conn, "show.html")
  end

The problem I am facing is that I am unable to redirect or render once I’ve reached the create action. I’ve been able to solve this problem in other projects by using the DropZone event “queueComplete”:

        queuecomplete: function queuecomplete() {
          let dropzone = document.getElementById("mydropzone");
          window.location.href = dropzone.action;
        },

I am unable to use this workout around this time because instead of just returning to an index page, I need to go to a page using a specific identifier. If anyone has an idea that can point me in the right direction that would be great. Thanks.`

Showing Posts 1 to 2

kynoshi

kynoshi

Hi asnyder002!

The scenario you are describing seems basically clear to me, only in the details i have the feeling to miss some crucial information to give a good answer to you. Here is some analysis of the above scenario:

a) Given, that the action is called properly and the upload did well, you code looks like the redirection target should be the route of WhateverWeb.AdminUpload.show which i assume is show(conn, %{"csv_sha256" => csv_sha256} = params) as listed above. You properly redirect from create to show which should render a list of shipments, matching the csv_sha256 parameter. App.list_shipments_by_csv_sha256() is probably missing a parameter here, but that’s probably not the single point of failure here.

b) As I see in the template code, you seem to render a default, html form. Since you relate to the :create action, this is most likely a POST/PUT HTTP call. I cannot see anything here, that turns the default HTTP Post (with page reload) into an Ajax call or alike. So, the form will probably behave that way.

Assumption: I am not seeing any submit button but a DropZone field. I’ve never used DropZone but due to the missing submit button and the fact, that your above controller code looks fine AND you are pointing to the fact, that you’ve used a JS callback in the past to delegate after upload, come to the conclusion, that you actually seem to be confusing/mixing up between “real/basic” HTML Forms which do full HTTP POST and “nice/modern/dynamic” HTTP Forms, that make heacy use of JS callbacks,

Here are some things for you in order to figure out what happens and to probably solve the problem yourself:

Assuming you would to keep DropZone:

  1. Stili inside your create action you want to stop using Phoenix for redirection and just return the “external reachable” URL of the show endpoint/action.
  2. put some console.log(arguments) right as first line of you queuecomplete: function queuecomplete() callback. Even better use the browsers debugging console and put the debugger; statement instead of console.log. You will want to ensure that the callback is even activated and if it is activated, what the actual response is the complete url including sha256 hash from your create action.
  3. if your create response reaches your JS callback, just fiddle the URL from the resposne and use it as value for window.location.href

This might hopefully do the trick for you. If understood your overall goal incorrect and you want to accomplish something else, it would work best for me, if you’d upload a minimal, “runnable”, sample project github or alike.

asnyder002

asnyder002 OP

Hey, thank you so much. This was extremely helpful. I felt I was missing something, from inexperience, and this lead me to learn a lot.

In the create action I sent this as a response

    conn
    |> send_resp(:ok, Routes.admin_upload_path(conn, :show, csv_sha256))

I then found a “success” event that gets triggered in DropZone and took the URL from the response and set the location. Thanks again man.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
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...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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