Hotwire turbo frame update with active storage uploads

I have an active storage file upload for the Projects model. What I want to have happen is to select the files to upload and update the list of files underneath the upload input with hotwire. I wasn’t sure what the best way would be to do that. Do I need to call that from an active storage controller or something or should I be able to do it from the projects controller or model?

I have done this while using drop zone + active storage I did the direct upload and got a blob_signed_id back then I made a request from javascript to a controller and then you can find the blob by using find_signed

// file_uploads_controller.rb
def create
  project = Project.find(params[:project_id])
  blob = ActiveStorage::Blob.find_signed(params[:blob_signed_id])
  project.files << blob
  project.save
  render turbo_stream: turbo_stream.append("file-uploads", partial: "uploaded_file", local: { file: blob })
end
1 Like