BillBryson

BillBryson

I’m trying to use waffle to handle the upload with LiveView uploads and receive the following error: [error] {:error, :invalid_file_path}.

I’m building a %Plug.Upload{content_type: content_type, filename: filename, path: path} struct which is then sent over as the “image” attribute to my schema that has my Waffle uploader type for field image. But in the cast_attachments function it returns the error changeset:

#Ecto.Changeset<
  action: nil,
  changes: %{title: "foo"},
  errors: [
    image: {"is invalid",
     [type: MyAppWeb.Uploaders.PostImage.Type, validation: :cast]}
  ],
  data: #MyApp.Blog.Post<>,
  valid?: false
>

The attributes being passed to the schema changeset are:

%{
  "title" => "foo",
  "image" => %Plug.Upload{
    content_type: "image/png",
    filename: "blog-title.png",
    path: "/var/folders/mt/9c2zqzy93tg5xfl7317j7m340000gn/T//plug-1619/live_view_upload-1619366353-634670199203471-4"
  }
}

I have tried without the LiveView and it works, but only difference I can see is in the path set on the upload.

Showing Posts 1 to 9

cenotaph

cenotaph

Liveview already has a dedicated file upload section with the necessary methods, js functions.

Is there a specific reason you don’t want to use those and replicate the work with waffle integration?

BillBryson

BillBryson OP

Mostly because I am making use of the image transformations/versions that Waffle makes easy to do. If my situation were more direct upload and no any image manipulation I would use the those instructions.

cenotaph

cenotaph

Regardless of your answer, there is no plug on LIve View. Transfer happens with the socket, help of JS and multipart binary form.

That is why cast is coming empty

cenotaph

cenotaph

Do you use imagemagick for your modifications? If so it will just be an addition to the example code.

convert -define jpeg:size=200x200 original.jpeg -thumbnail 100x100^ -gravity center -extent 100x100 thumbnail.jpeg

defp consume_photos(socket) do
   ...
   File.cp!(meta.path, dest)
   System.cmd("convert", ["define", "jpeg:size"...... dest])
   ...
end
BillBryson

BillBryson OP

I do see other people have had luck LiveView support · Issue #71 · elixir-waffle/waffle · GitHub and am trying to follow that example of building my own %Plug.Upload{} that then is passed into the changeset.

Yes, you are right that I could simply write my own image conversions, but our team preference is to use a standardized library that has tests/documentation.

kokolegorille

kokolegorille

The path is the filename… You might have to copy the file to a tmp file, then use it in Plug.Upload.

BillBryson

BillBryson OP

Oh do I have this mixed up? Should it be:

%Plug.Upload{
    content_type: "image/png",
    filename: "/var/folders/mt/9c2zqzy93tg5xfl7317j7m340000gn/T//plug-1619/live_view_upload-1619366353-634670199203471-4"
  }
kokolegorille

kokolegorille

Maybe, You should try :slight_smile:

I remember having this issue too. Until I realized path was the filename.

But I do not remember why I think it was easier to make a copy first, instead of using the tmp file directly.

BillBryson

BillBryson OP

Sorry I was away from the computer. I have tried this now still with no luck. I did compare the contents of the %Plug.Upload{} without LiveView:

...
    "image" => %Plug.Upload{
      content_type: "image/png",
      filename: "post-image.png",
      path: "/var/folders/mt/9c2zqzy93tg5xfl7317j7m340000gn/T//plug-1619/multipart-1619366663-722432590674384-4"
    }
...

This does work without live view. And changing the path to filename did not work. I will try the copy to a tmp file and then use that in the %Plug.Upload{}. I am still not sure why this does not work.

— 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
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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 &amp; 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
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews