diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-09-11 17:56:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-11 17:56:29 -0400 |
commit | e9ae7a1514d660fee8cacc6a9aa7524f6f4617e3 (patch) | |
tree | 3cd40e9cb322693bbcf09fcfc575d18ef427fb92 /activestorage | |
parent | ab0eed599b9cb2b62eab79ae761464ea732b2e70 (diff) | |
parent | 0d4ba40688785ad65da1af36b3ad8efd8e14505e (diff) | |
download | rails-e9ae7a1514d660fee8cacc6a9aa7524f6f4617e3.tar.gz rails-e9ae7a1514d660fee8cacc6a9aa7524f6f4617e3.tar.bz2 rails-e9ae7a1514d660fee8cacc6a9aa7524f6f4617e3.zip |
Merge pull request #33795 from marceloperini/marceloperini/33450-active-storage
Fix zero-byte files upload in #33630
Diffstat (limited to 'activestorage')
-rw-r--r-- | activestorage/app/models/active_storage/blob/identifiable.rb | 6 | ||||
-rw-r--r-- | activestorage/test/fixtures/files/empty_file.txt | 0 | ||||
-rw-r--r-- | activestorage/test/service/s3_service_test.rb | 7 |
3 files changed, 12 insertions, 1 deletions
diff --git a/activestorage/app/models/active_storage/blob/identifiable.rb b/activestorage/app/models/active_storage/blob/identifiable.rb index 049e45dc3e..2c17ddc25f 100644 --- a/activestorage/app/models/active_storage/blob/identifiable.rb +++ b/activestorage/app/models/active_storage/blob/identifiable.rb @@ -15,6 +15,10 @@ module ActiveStorage::Blob::Identifiable end def download_identifiable_chunk - service.download_chunk key, 0...4.kilobytes + if byte_size.positive? + service.download_chunk key, 0...4.kilobytes + else + "" + end end end diff --git a/activestorage/test/fixtures/files/empty_file.txt b/activestorage/test/fixtures/files/empty_file.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/activestorage/test/fixtures/files/empty_file.txt diff --git a/activestorage/test/service/s3_service_test.rb b/activestorage/test/service/s3_service_test.rb index 4bfcda017f..559aa028f2 100644 --- a/activestorage/test/service/s3_service_test.rb +++ b/activestorage/test/service/s3_service_test.rb @@ -31,6 +31,13 @@ if SERVICE_CONFIGURATIONS[:s3] end end + test "upload a zero byte file" do + blob = directly_upload_file_blob filename: "empty_file.txt", content_type: nil + user = User.create! name: "DHH", avatar: blob + + assert_equal user.avatar.blob, blob + end + test "signed URL generation" do url = @service.url(@key, expires_in: 5.minutes, disposition: :inline, filename: ActiveStorage::Filename.new("avatar.png"), content_type: "image/png") |