SubmissionsController: Send Content-Length if possible
This commit is contained in:
@ -54,7 +54,9 @@ class SubmissionsController < ApplicationController
|
||||
zio.write(File.read(File.join(scripts_path, file)))
|
||||
end
|
||||
end
|
||||
send_data(stringio.string, filename: "#{@submission.exercise.title.tr(' ', '_')}.zip")
|
||||
zip_data = stringio.string
|
||||
response.set_header('Content-Length', zip_data.size)
|
||||
send_data(zip_data, filename: "#{@submission.exercise.title.tr(' ', '_')}.zip")
|
||||
end
|
||||
|
||||
def download_file
|
||||
@ -63,6 +65,7 @@ class SubmissionsController < ApplicationController
|
||||
if @file.native_file?
|
||||
redirect_to protected_upload_path(id: @file.id, filename: @file.filepath)
|
||||
else
|
||||
response.set_header('Content-Length', @file.size)
|
||||
send_data(@file.content, filename: @file.name_with_extension, disposition: 'attachment')
|
||||
end
|
||||
end
|
||||
@ -93,6 +96,7 @@ class SubmissionsController < ApplicationController
|
||||
url = render_protected_upload_url(id: @file.id, filename: @file.filepath)
|
||||
redirect_to AuthenticatedUrlHelper.sign(url, @file)
|
||||
else
|
||||
response.set_header('Content-Length', @file.size)
|
||||
send_data(@file.content, filename: @file.name_with_extension, disposition: 'inline')
|
||||
end
|
||||
end
|
||||
|
@ -17,6 +17,8 @@ module CodeOcean
|
||||
before_validation :hash_content, if: :content_present?
|
||||
before_validation :set_ancestor_values, if: :incomplete_descendent?
|
||||
|
||||
attr_writer :size
|
||||
|
||||
belongs_to :context, polymorphic: true
|
||||
belongs_to :file, class_name: 'CodeOcean::File', optional: true # This is only required for submissions and is validated below
|
||||
alias ancestor file
|
||||
@ -128,5 +130,13 @@ module CodeOcean
|
||||
def visible
|
||||
!hidden
|
||||
end
|
||||
|
||||
def size
|
||||
@size ||= if native_file?
|
||||
native_file.size
|
||||
else
|
||||
content.size
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user