admin管理员组

文章数量:1122832

I'm wanting to have the user select a data file and select a directory (different than the data file location) for images to be imported using active_storage as a background_job in Ruby on Rails.

What type of field can I use in form_with that will allow the file path to be saved for active storage to use after the data file has been imported?

I tried a file_field :photos_path to select a directory in the form

Then in the controller get the path in the params

    if params[:report][:photos_path].present?
      @report.photos_path = params[:report][:photos_path].path
      p @report.photos_path
    end

but that returns the active storage tmp path

11:27:18 web.1  | "/var/folders/bm/6t88t37133d2b6_j1npz5qn80000gn/T/RackMultipart20241121-84847-g5ihzm.csv"

The actual goal is to provide a unique folder directory for active storage to use to import images after the data file has already been imported.

record.photo.attach(io: File.open(Rails.public_path.join("#{file_path}/#{image_name}")), filename: "#{image_name}.jpg", content_type: "image/jpeg", identify: false)

本文标签: rubyrails formwith save file path to database for active storage to import imagesStack Overflow