0

I'm trying to upload a .zip file and then parse it using rubyzip:

def upload
  require 'zip'
  @file = params[:software].tempfile
  Zip::File.open(@file.path) do |zipfile|
    #Parse file... 
  end
end

I can't do this, I get a File not found error at Zip::File.open. I assume the problem is that when the user uploads the file it gets sent to the Windows Temp folder, and I my application can't get to it.

If I copy this .zip file to the inside of my folder I can access it just fine, but I don't want to do it this way for safety reasons.

bpromas
  • 684
  • 1
  • 11
  • 25
  • Why can't your application access it? When you say "outside application" what do you mean? – tadman May 19 '15 at 18:43
  • Every file that composes my application are in `C:\Aplic\upload` and so my guess is that my application can't access what's outside of this path. The thing is that when the user uploads a file it gets sent to `C:\Users\BRUNO1~1\AppData\Local\Temp\` (that's the value of `@file.path`) and so `Zip::File.open` is unable to get to it. – bpromas May 19 '15 at 18:54
  • 1
    If you're running this code inside your application that should work. Maybe there's something else wrong here. Does `File.exist?(@file.path)` return `true`? Remember that these files are deleted almost immediately when your request is finished, and on UNIX-type systems are actually deleted *before* being passed through to your method. It's just a file handle to data. You may want to read in via the file handle instead of via the path. – tadman May 19 '15 at 19:03
  • Uhm. What the hell? After putting `puts File.exist?(@file.path)` right before my `Zip::File.open` everything suddenly worked. And if I remove it or move it to after `Zip::File.open` then it doesn't run anymore. – bpromas May 19 '15 at 19:08

0 Answers0