Fix bug that prevented binary file uploads

This commit is contained in:
Sebastian Serth
2021-11-02 10:31:38 +01:00
parent ebec5bac04
commit 620dac935a

View File

@ -230,12 +230,11 @@ raise: false
if exercise_params if exercise_params
exercise_params[:files_attributes].try(:each) do |index, file_attributes| exercise_params[:files_attributes].try(:each) do |index, file_attributes|
if file_attributes[:content].respond_to?(:read) if file_attributes[:content].respond_to?(:read)
file_params = exercise_params[:files_attributes][index]
if FileType.find_by(id: file_attributes[:file_type_id]).try(:binary?) if FileType.find_by(id: file_attributes[:file_type_id]).try(:binary?)
file_params[:content] = nil file_attributes[:native_file] = file_attributes[:content]
file_params[:native_file] = file_attributes[:content] file_attributes[:content] = nil
else else
file_params[:content] = file_attributes[:content].read.detect_encoding!.encode.delete("\x00") file_attributes[:content] = file_attributes[:content].read.detect_encoding!.encode.delete("\x00")
end end
end end
end end