0

I have a problem while uploading a file under Mac. It was fine under windows dev environment, and ok under ubuntu prod, but throw this under Mac os 10.6.8 when I try to upload and parse a file:

Errno::ENOENT in ProductsController#import_adjust

No such file or directory - /var/folders/v8/v8lBbdWcGJmntpbJRzGcfU+++TI/-Tmp-/RackMultipart20120824-71301-1aqop0s

Here is a form:

<%= form_for :upload, :html => {:multipart => true}, :url => {action: "upload"} do |f| %>
  <%= f.file_field :my_file %>
  <%= f.submit "Upload" %>
<% end %>

And this is a code:

def import_adjust
    case params[:commit]
      when "Adjust"
        @col_default = params[:col_data]
        #abort @col_default.to_yaml
        #update csv reader with form data, restore filters  from params
      when "Complete"
        #all ok, read the whole file
        #abort params.to_yaml
        self.import_complete
        return
      else
        @col_default = nil
    end
    #read first part of the file
    @tmp = session[:import_file]
    @csv = []
    source = CSV.open @tmp, {col_sep: ";"}

    5.times do
      line = source.readline
      if line.size>0
        @line_size = line.size
        @csv.push line
      end
    end

    #generate a selection array
    #selection = select_tag 'col_data[]', options_for_select([['name','name'], ['brand','brand'], ['delivery_time','delivery_time'], ['price','price']])
    #@csv = [selection * line_size] + @csv
  end
lifecoder
  • 1,424
  • 1
  • 14
  • 29
  • Did your /tmp filled up? check http://stackoverflow.com/questions/4590229/why-are-rackmultipart-files-persisting-in-my-rails-tmp-directory and clean /tmp if necessary – Ted Shaw Aug 24 '12 at 10:52
  • Mentioned tmp folder looks pretty empty for garbage collector, and other files there are not cleared after upload - but I don't know for sure how Mac's collector works. Also I've try with ENV setting in the environment.rb, but it doesn't work for me. – lifecoder Aug 24 '12 at 12:50
  • Oh, Webrick doesn't pick ENV on the fly, it works after server reboot. Otherwise nothig changed - now temp file points to the RAILS_ROOT/tmp, and uploaded file cleared lighting fast, right after the upload, which kills me since I need it for several times, but couldn't access it right after upload (it still works time to time for the first controller run, but most of the time it removed already) – lifecoder Aug 24 '12 at 12:59
  • Got it. I have a redirect right after upload, and Mac (or Rails under mac) have a very strict opinion about tempfiles lifetime - the next cotroller execution kills the temp file. So it looks like I need to move it on upload if I want to work with the file anymore, or doing something with garbage collector - but have no idea how to deal with it. – lifecoder Aug 24 '12 at 13:07

0 Answers0