My app (locally) raises ActiveStorage::IntegrityError
error, whenever it tries to attach a file. How can I get out of this error?
I have only one has_one_attached
and I don't know how that error gets in the way.
# model
has_one_attached :it_file
Tempfile.open do |temp_file|
# ...
it_file.attach(io: temp_file, filename: 'filename.csv', content_type: 'text/csv')
end
# storage.yml
local:
service: Disk
root: <%= Rails.root.join("storage") %>
EDIT: it can be related with deleting storage/
directory (it happened after I deleted that) or it can be because it's happening in a job (the full error was Error performing ActivityJob (Job ID: .. ) from Async( .. ) in .. ms: ActiveStorage::IntegrityError (ActiveStorage::IntegrityError)
And this does not add files to storage/
folder but it's generating folders under it when I tried to attach them.
As mentioned in the comments, one reason this can happen is that the file object is at the end of the file, which was the problem in this case. It could be fixed here with temp_file.rewind
.
Very weird. After update to rails 6.0 I must recalculate some checksums. Yes I used dokku,docker. It was fine before update.
# Disk service is in use for ActiveStorage
class ProjectImage < ApplicationRecord
has_one_attached :attachment
end
# update all checksums
ProjectImage.all.each do |image|
blob = image.attachment.blob
blob.update_column(:checksum, Digest::MD5.base64digest(File.read(blob.service.path_for(blob.key))))
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With