Alvinkariuki

Alvinkariuki

Failed file upload test

I’m currently trying to tests file upload functionality for multiple files, here is a snippet of the code in a form

      files =
        file_input(live, "#upload_form", :files, [
          %{
            last_modified: 1_551_913_973,
            name: "file_1.png",
            content: File.read!("test/live/sample.png"),
            size: 512_623,
            type: "image/png"
          },
          %{
            last_modified: 1_551_913_974,
            name: "file_2.png",
            content: File.read!("test/live/sample.png"),
            size: 512_623,
            type: "image/png"
          }
        ])
       
        form_preupload =
        live
        |> form("#upload_form",
            some_form: %{
              user_name: "Employ",
              start_date: "2023-07-19",
            }
          }
        )

      render_upload(
        files,
        "file_1.png"
      )
    
     render_upload(
        files,
        "file_1.png"
      )

    render_submit(form_preupload)

everything works fine till the render submit. to which I get this error

** (RuntimeError) cannot consume uploaded file that is still in progress

the files are being consumed with consume_uploaded_entry/3 in a loop for loop

What could the problem possibly be

Most Liked

trisolaran

trisolaran

Check whether the size value you pass to file_input matches the size of the content. I get the error you’re seeing when they differ.

To be on the safe side, do not hard code the size value but set it directly from the file content. This is what I do in one of my tests:

      file_content = File.read!(Path.join(__DIR__, "two_sigma.csv"))

      file_upload =
        file_input(view, "#resolution_form", :ledes_file, [
          %{
            name: new_file_name,
            type: "text/csv",
            size: byte_size(file_content),
            content: file_content
          }
        ])

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement