2017-09-07 17:27:04 -04:00
|
|
|
module SendFileUpload
|
2018-03-09 09:16:06 -05:00
|
|
|
def send_upload(file_upload, send_params: {}, redirect_params: {}, attachment: nil, disposition: 'attachment')
|
2017-09-07 17:27:04 -04:00
|
|
|
if attachment
|
2018-03-09 09:16:06 -05:00
|
|
|
redirect_params[:query] = { "response-content-disposition" => "#{disposition};filename=#{attachment.inspect}" }
|
2018-05-14 00:43:48 -04:00
|
|
|
# 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'
|
2018-03-09 09:16:06 -05:00
|
|
|
send_params.merge!(filename: attachment, disposition: disposition)
|
2017-09-07 17:27:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if file_upload.file_storage?
|
|
|
|
send_file file_upload.path, send_params
|
2018-03-09 09:16:06 -05:00
|
|
|
elsif file_upload.class.proxy_download_enabled?
|
2018-03-22 14:37:47 -04:00
|
|
|
headers.store(*Gitlab::Workhorse.send_url(file_upload.url(**redirect_params)))
|
|
|
|
head :ok
|
2017-09-07 17:27:04 -04:00
|
|
|
else
|
|
|
|
redirect_to file_upload.url(**redirect_params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|