diff options
author | George Claghorn <george@basecamp.com> | 2017-12-07 15:14:22 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2017-12-07 15:16:24 -0500 |
commit | e8286ee272a3e51daebc198519accd1f6895a8d2 (patch) | |
tree | 215e6f622abb372ba24e3f8397dd6d50e1f86105 /activestorage/lib/active_storage | |
parent | e8c3b58cb6e1dd204dd586f1cf6c3e482fb80abe (diff) | |
download | rails-e8286ee272a3e51daebc198519accd1f6895a8d2.tar.gz rails-e8286ee272a3e51daebc198519accd1f6895a8d2.tar.bz2 rails-e8286ee272a3e51daebc198519accd1f6895a8d2.zip |
Fix customizing Content-Type via GCS service URLs
Diffstat (limited to 'activestorage/lib/active_storage')
-rw-r--r-- | activestorage/lib/active_storage/service/gcs_service.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activestorage/lib/active_storage/service/gcs_service.rb b/activestorage/lib/active_storage/service/gcs_service.rb index c13ce4786d..6f6f4105fe 100644 --- a/activestorage/lib/active_storage/service/gcs_service.rb +++ b/activestorage/lib/active_storage/service/gcs_service.rb @@ -16,7 +16,13 @@ module ActiveStorage def upload(key, io, checksum: nil) instrument :upload, key: key, checksum: checksum do begin - bucket.create_file(io, key, md5: checksum) + # The official GCS client library doesn't allow us to create a file with no Content-Type metadata. + # We need the file we create to have no Content-Type so we can control it via the response-content-type + # param in signed URLs. Workaround: let the GCS client create the file with an inferred + # Content-Type (usually "application/octet-stream") then clear it. + bucket.create_file(io, key, md5: checksum).update do |file| + file.content_type = nil + end rescue Google::Cloud::InvalidArgumentError raise ActiveStorage::IntegrityError end |