Set Content-Type to fixed value for all download actions
This commit is contained in:
@ -23,7 +23,7 @@ module CodeOcean
|
|||||||
raise Pundit::NotAuthorizedError if @embed_options[:disable_download] || @file.filepath != params[:filename]
|
raise Pundit::NotAuthorizedError if @embed_options[:disable_download] || @file.filepath != params[:filename]
|
||||||
|
|
||||||
real_location = Pathname(@file.native_file.current_path).realpath
|
real_location = Pathname(@file.native_file.current_path).realpath
|
||||||
send_file(real_location, type: @file.native_file.content_type, filename: @file.name_with_extension, disposition: 'attachment')
|
send_file(real_location, type: 'application/octet-stream', filename: @file.name_with_extension, disposition: 'attachment')
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_protected_upload
|
def render_protected_upload
|
||||||
|
@ -57,7 +57,7 @@ class SubmissionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
zip_data = stringio.string
|
zip_data = stringio.string
|
||||||
response.set_header('Content-Length', zip_data.size)
|
response.set_header('Content-Length', zip_data.size)
|
||||||
send_data(zip_data, filename: "#{@submission.exercise.title.tr(' ', '_')}.zip")
|
send_data(zip_data, type: 'application/octet-stream', filename: "#{@submission.exercise.title.tr(' ', '_')}.zip", disposition: 'attachment')
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_file
|
def download_file
|
||||||
@ -67,7 +67,7 @@ class SubmissionsController < ApplicationController
|
|||||||
redirect_to protected_upload_path(id: @file.id, filename: @file.filepath)
|
redirect_to protected_upload_path(id: @file.id, filename: @file.filepath)
|
||||||
else
|
else
|
||||||
response.set_header('Content-Length', @file.size)
|
response.set_header('Content-Length', @file.size)
|
||||||
send_data(@file.content, filename: @file.name_with_extension, disposition: 'attachment')
|
send_data(@file.content, type: 'application/octet-stream', filename: @file.name_with_extension, disposition: 'attachment')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ describe CodeOcean::FilesController do
|
|||||||
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.mp4' } }
|
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.mp4' } }
|
||||||
|
|
||||||
expect_assigns(file: :file)
|
expect_assigns(file: :file)
|
||||||
expect_content_type('video/mp4')
|
expect_content_type('application/octet-stream')
|
||||||
expect_http_status(:ok)
|
expect_http_status(:ok)
|
||||||
|
|
||||||
it 'sets the correct filename' do
|
it 'sets the correct filename' do
|
||||||
|
@ -85,7 +85,7 @@ describe SubmissionsController do
|
|||||||
|
|
||||||
expect_assigns(file: :file)
|
expect_assigns(file: :file)
|
||||||
expect_assigns(submission: :submission)
|
expect_assigns(submission: :submission)
|
||||||
expect_content_type('text/javascript')
|
expect_content_type('application/octet-stream')
|
||||||
expect_http_status(:ok)
|
expect_http_status(:ok)
|
||||||
|
|
||||||
it 'sets the correct filename' do
|
it 'sets the correct filename' do
|
||||||
|
Reference in New Issue
Block a user