MatijaL

MatijaL

Hi,

I have a small LiveView app deployed on Fly.io and sometimes, when uploading an image, I encounter strange behavior. I click browse, I select image and image preview shows, I click submit and image is uploaded, this is how it should work and works most of the time, but sometimes, something happens and uploading breaks.

In fly logs, I get {:error, :enoent} error. I used dbg to see if the file exists, and it does. So, the file exists and when it should be copied from /tmp/ folder to /uploads folder, it breaks for some reason.

As I already mentioned, this is happening only sometimes, most of the time it works fine and that makes it quite hard to debug. This doesn’t happen on my dev machine. Do you have any idea what could be causing this kind of behavior?

FILE EXISTS: /tmp/plug-1711-iIkC/live_view_upload-1711634767-822835485870-1
COPY ERROR: enoent
[lib/myapp/helpers/file_manager.ex:60: MyApp.Helpers.FileManager.copy_file/2]
path #=> "/tmp/plug-1711-iIkC/live_view_upload-1711634767-822835485870-1"
[lib/myapp/helpers/file_manager.ex:61: MyApp.Helpers.FileManager.copy_file/2]
dest #=> "/uploads/tmp/live_view_upload-1711634767-822835485870-1.jpg"
warning: consuming uploads requires a return signature matching:
    {:ok, value} | {:postpone, value}
got:
    {:error, :enoent}
defp copy_file(path, dest) do
    case File.cp(path, dest) do
      :ok ->
        {:ok, nil}
      {:error, reason} ->
        {:error, reason}
    end
  end

Showing Posts 1 to 4

kokolegorille

kokolegorille

Maybe it has to do with the tmp file being deleted after the process ends?

Did this happen for big image files?

Do You try to save in async mode?

al2o3cr

al2o3cr

The log shows it’s being copied to /uploads/tmp/live_view_upload-1711634767-822835485870-1.jpg - does that tmp subdirectory always exist inside uploads?

The :enoent from cp is what I’d expect when it doesn’t exist.

MatijaL

MatijaL OP

No, the file in the /tmp/ folder exists when the error is thrown so the process doesn’t ends before the error.

It doesn’t matter, I’ve tested with several images, from 200kb to 3mb, and it can happen to any of them.

No.

Files are uploaded by default to /tmp dir. Then, I copy them to /uploads/tmp (this is where the problem occurs) where I do some transformations to the image and then, the image is saved to a custom user dir. After image is successfully saved to the user dir, image is removed from /uploads/tmp but the subdir tmp remains.

Exactly, that’s the problem which I don’t understand. I’ve checked with File.exists?() and the file is there even after the error is thrown.

tj0

tj0

Probably not it, but on fly is everything happening on the same server/machine? Wondering if the connection is occasionally getting bounced to another machine which would explain it. The code looks like it would only execute on one machine though.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
Damirados
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews