diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index aad9dad83..d275da5e2 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -57,6 +57,16 @@ class ImportsController < ApplicationController end end + if request.get? + file_path = @import.filepath + file_encoding = @import.settings['encoding'] + @preview_content = File.open(file_path, "r:#{file_encoding}:UTF-8") do |f| + # Read only the header and the first 3 lines + # Same as the default value of the Import#first_rows + f.each_line.first(4).join + end + end + rescue CSV::MalformedCSVError, EncodingError => e if e.is_a?(CSV::MalformedCSVError) && !e.message.include?('Invalid byte sequence') flash.now[:error] = l(:error_invalid_csv_file_or_settings, e.message) diff --git a/app/views/imports/settings.html.erb b/app/views/imports/settings.html.erb index 1342b55fb..53d09c357 100644 --- a/app/views/imports/settings.html.erb +++ b/app/views/imports/settings.html.erb @@ -30,3 +30,8 @@

<%= submit_tag l(:label_next).html_safe + " »".html_safe, :name => nil %>

<% end %> + +
+<%= l(:label_file_content_preview) %> +
<%= @preview_content %>
+