Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-08-14 01:36:15 +0300
committerStan Hu <stanhu@gmail.com>2018-09-06 03:01:54 +0300
commit262b974123d22b5d6b662b232ca4792d7998a166 (patch)
tree223b600596a24fa4a4cd8436f8317d2874fb98ce /app/controllers
parent9dd34eac14a94e58999c335a175e06067f1092fa (diff)
Fix attachments not displaying inline with Google Cloud Storage
There were several issues: 1. With Google Cloud Storage, we can't override the Content-Type with Response-Content-Type once it is set. Setting the value to `application/octet-stream` doesn't buy us anything. GCS defaults to `application/octet-stream`, and AWS uses `binary/octet-stream`. Just remove this `Content-Type` when we upload new files. 2. CarrierWave and fog-google need to support query parameters: https://github.com/fog/fog-google/pull/409/files, https://github.com/carrierwaveuploader/carrierwave/pull/2332/files. CarrierWave has been monkey-patched until an official release. 3. Workhorse also needs to remove the Content-Type header in the request (https://gitlab.com/gitlab-org/gitlab-workhorse/blob/ef80978ff89e628c8eeb66556720e30587d3deb6/internal/objectstore/object.go#L66), or we'll get a 403 error when uploading due to signed URLs not matching the headers. Upgrading to Workhorse 6.1.0 for https://gitlab.com/gitlab-org/gitlab-workhorse/merge_requests/297 will make Workhorse use the headers that are used by Rails. Closes #49957
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/concerns/send_file_upload.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/controllers/concerns/send_file_upload.rb b/app/controllers/concerns/send_file_upload.rb
index 237c93daee8..382ec91f771 100644
--- a/app/controllers/concerns/send_file_upload.rb
+++ b/app/controllers/concerns/send_file_upload.rb
@@ -1,7 +1,11 @@
module SendFileUpload
def send_upload(file_upload, send_params: {}, redirect_params: {}, attachment: nil, disposition: 'attachment')
if attachment
- redirect_params[:query] = { "response-content-disposition" => "#{disposition};filename=#{attachment.inspect}" }
+ # Response-Content-Type will not override an existing Content-Type in
+ # Google Cloud Storage, so the metadata needs to be cleared on GCS for
+ # this to work. However, this override works with AWS.
+ redirect_params[:query] = { "response-content-disposition" => "#{disposition};filename=#{attachment.inspect}",
+ "response-content-type" => guess_content_type(attachment) }
# By default, Rails will send uploads with an extension of .js with a
# content-type of text/javascript, which will trigger Rails'
# cross-origin JavaScript protection.
@@ -18,4 +22,14 @@ module SendFileUpload
redirect_to file_upload.url(**redirect_params)
end
end
+
+ def guess_content_type(filename)
+ types = MIME::Types.type_for(filename)
+
+ if types.present?
+ types.first.content_type
+ else
+ "application/octet-stream"
+ end
+ end
end