Correct checksum of big files stored on AWS S3

This commit is contained in:
Maikel Linke
2022-06-02 12:13:34 +10:00
parent 4facab0335
commit 076efd653d
2 changed files with 18 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
# When migrating to Active Storage, we used Amazon's ETag for the blob
# checksum. But big files have been uploaded in chunks and then the checksum
# differs. We need to recalculate the checksum for large files.
class ComputeChecksumForBigFiles < ActiveRecord::Migration[6.1]
def up
blobs_with_incorrect_checksum.find_each do |blob|
md5 = Digest::MD5.base64digest(blob.download)
blob.update(checksum: md5)
end
end
def blobs_with_incorrect_checksum
ActiveStorage::Blob.
where(service_name: "amazon").
where("byte_size >= 20000000")
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_04_10_162955) do
ActiveRecord::Schema.define(version: 2022_06_02_013938) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"