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

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement