Skip to content
Snippets Groups Projects

Encode Content-Disposition filenames

Merged Stan Hu requested to merge sh-encode-content-disposition into master
All threads resolved!
@@ -3,18 +3,18 @@
module SendFileUpload
def send_upload(file_upload, send_params: {}, redirect_params: {}, attachment: nil, proxy: false, disposition: 'attachment')
if attachment
disposition = ::Gitlab::ContentDisposition.format(disposition: disposition, filename: attachment)
response_disposition = ::Gitlab::ContentDisposition.format(disposition: 'attachment', filename: attachment)
# 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,
redirect_params[:query] = { "response-content-disposition" => response_disposition,
"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.
send_params[:content_type] = 'text/plain' if File.extname(attachment) == '.js'
send_params.merge!(filename: attachment, disposition: disposition)
send_params.merge!(filename: attachment, disposition: response_disposition)
end
if file_upload.file_storage?
Loading