diff options
author | George Claghorn <george@basecamp.com> | 2018-05-28 16:28:46 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-05-28 16:28:46 -0400 |
commit | 1bdaccc0b8cf8aac0dc833d6db14b9a902593ff5 (patch) | |
tree | 47c7fe84ded16a785feb86f42faa225175d4a8c4 /activestorage/lib/active_storage/downloader.rb | |
parent | 34cc301f03aea2e579d6687a9ea9782afc1089a0 (diff) | |
download | rails-1bdaccc0b8cf8aac0dc833d6db14b9a902593ff5.tar.gz rails-1bdaccc0b8cf8aac0dc833d6db14b9a902593ff5.tar.bz2 rails-1bdaccc0b8cf8aac0dc833d6db14b9a902593ff5.zip |
Verify integrity after chunked download
Diffstat (limited to 'activestorage/lib/active_storage/downloader.rb')
-rw-r--r-- | activestorage/lib/active_storage/downloader.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activestorage/lib/active_storage/downloader.rb b/activestorage/lib/active_storage/downloader.rb index 0e7039e104..5953fd08fb 100644 --- a/activestorage/lib/active_storage/downloader.rb +++ b/activestorage/lib/active_storage/downloader.rb @@ -10,6 +10,7 @@ module ActiveStorage def download_blob_to_tempfile open_tempfile do |file| download_blob_to file + verify_integrity_of file yield file end end @@ -34,6 +35,12 @@ module ActiveStorage file.rewind end + def verify_integrity_of(file) + unless Digest::MD5.file(file).base64digest == checksum + raise ActiveStorage::IntegrityError + end + end + def tempfile_extension_with_delimiter blob.filename.extension_with_delimiter end |