I'm setting up an account profil system and i want to support an avatar with active_storage in my rails app. I'm expecting to see my avatar but instead i've got thisbroken_pics
If i open the picture in an other tabs he send me this app/controllers/active_storage/disk_controller.rb line 10-17:
def show
if key = decode_verified_key
serve_file disk_service.path_for(key[:key]), content_type: key[:content_type], disposition: key[:disposition]
else
head :not_found
end
end
the problem come from this line or above serve_file disk_service.path_for(key[:key]), content_type: key[:content_type], disposition: key[:disposition]
We just had this same issue. Turns out the implementation of ActiveStorage::DiskController#show changed from Rails 5.2.1 to Rails 5.2.2. See 5.2.1 vs 5.2.2
The active_storage-postgresql
gem relied on the behaviour of Rails 5.2.1. It looks like there is a PR that has just been merged to fix this, so I expect there will soon be a new release of the gem to restore Rails compatibility. Keep an eye on https://rubygems.org/gems/active_storage-postgresql .
As a temporary fix, we added a controller action like so to download the blobs via send_file
.
def download_file
attachment = ActiveStorage::Attachment.find(params[:id])
file = attachment.blob
data = file.download
send_data(data, type: file.content_type, filename: file.filename, disposition: "inline")
end
# then call like
download_file_path(model.file.id)