Rails Read csv file data with active storage
I think this could be another option (when it's local on disk). I used code from this answer
file_path = ActiveStorage::Blob.service.send(:path_for, materials_upload.csv_file.key)
CSV.foreach file_path, headers: true do
# ...
end
Use download
to obtain the file’s contents:
CSV.parse(materials_upload.csv_file.download, headers: true) do |row|
# ...
end