2

MY CODE BASE SETUP:

  • Ruby on Rails Deployed locally with Postgres
  • Production with Heroku (staging and production servers).

MY PROBLEM: Things are "seemingly" working on local machine (no hard errors) but NOT working in production. I believe my issue has to do with sending the proper information to the ruby, file.open() command.

I'm receiving the following error on my production(staging) server:

Errno::ENOENT in Projects#show Showing /app/app/views/projects/show.html.erb where line #276 raised:

No such file or directory @ rb_sysopen - https://[bucketname].s3.amazonaws.com/path/to/instance/of/file/file_name.stl

But if I take the resulting hyperlink and copy / paste it into my web browser, the file open / download menu is prompted. What am I doing wrong here?

BACKGROUND / HISTORY:

I haven't been able to resolve and I've scoured much of the stackoverflow questions looking for answers:

  1. ENOENT, no such file or directory but file exists ()
  2. File Exists But Receiving ENOENT Error (I'm not using node and my server restarts everytime I deploy)
  3. Rails 3: Errno::ENOENT exception (if CentOS is like Heroku, then we have a similar issue which no one seems to be able to answer). Not sure about my Tmp file situation. But this question sounds similar to my issue.
  4. Carrierwave, Rails 4; Errno::ENOENT (No such file or directory - identify) (might be relevant, but I'm not pulling an imagemagick file, I'm trying to parse a non-image file)
  5. Remove "www", "http://" from string (I tried stripping various portions of my path in order to feed the file.open() command the right format to no avail
  6. File.open, open and IO.foreach in Ruby, what is the difference? (this helped me understand the difference between each command type, which might be my issue).
  7. Open an IO stream from a local file or url (sounds again like a reliable fix but I don't know how to utilize this open command as the gem specifies a file.open() command vs. these open() commands).

I defined the following method in my "project model" (project.rb) which takes the project file from a particular instance and from the "project_file path" input, the gem parses an STL file for my webapp.

This particular gem--"STL_parser"--calls a file.open(filepath,'rb') command which is where I believe my app is running into issues. Here's the method I call in my model which calls the STL_parser gem:

def analyze_STL project_file

  if Rails.env.development? || Rails.env.test?
    full_path = project_file.current_path
  else
    full_path = project_file.url.to_s
  end

  parser = STLParser.new
  parser.process(full_path)
end

The RESULTS from each case and environment are as follows:

In Development:

    project_file.current_path

...for one particular instance yields on my mac:

    /Users/myname/full/path/to/file/on/laptop/unique_instance_file.stl

RESULT: app works on local machine AND if I copy/paste the above path into a web browser like Chrome, it prompts a file open / download menu.

In Production Environment:

    project_file.current_path 

RESULT:

Errno::ENOENT error - No such file or directory @ rb_sysopen -uploads/project/project_file/instance/instance_file.stl

and clearly lacks a subdomain, so in Production, I modified the path to call the file URL from AWS as seen above:

 project_file.url.to_s

    https://[bucketname].s3.amazonaws.com/path/to/instance/of/file/file_name.stl

RESULT:

Errno::ENOENT error - No such file or directory @ rb_sysopen -https://[bucketname].s3.amazonaws.com/path/to/instance/of/file/file_name.stl

...but if I copy / paste that path into my web browser, the file will prompt an open / download menu.

Thus the path seems to be pointing towards the correct to the file, but the file.open() command doesn't like that path format. Thoughts? I've been banging my head now for some time!

Possibilities:

  1. Is it a permissions thing with AWS? If so, why would other image files produced by other ruby Gems open fine in the same AWS bucket?

  2. When I apply the full-path as a hack...the URL format for my development environment, by simply creating a variable: hacked_path = "localhost:3000"+file_path

...this generates the Errno::ENOENT No such file or directory @ rb_sysopen error. But I can copy / paste that same path in my web browser and it opens a download prompt. So it seems like my browser is piecing together some information about how to open the file, but the Gem I'm calling in my webapp isn't that flexible. A friend of mine said something about my webapp not being able to read the "binary" while my local machine can?

  1. Is this an issue of file.open(filename, 'rb') vs. open(filename, 'rb')? I wouldn't even know how to modify the gem, but I could ask the developers for help.

  2. Is this because the my app doesn't have enough time to download the file from AWS before it tries to process the file?

  3. CORS permissions in AWS?

  4. Something else more simple I haven't thought of?

Thanks in advance for your help and feedback! Yes I know I need more programming fundamentals courses. Any online ones you'd recommend? Already took the one from onemonth.

Derek Hopper
  • 2,110
  • 12
  • 19
  • Your answer is in #7 as you posted above - by default you can't open a URL with the same code as a local file. Use `open-uri` as linked in #7. – stdunbar Dec 27 '17 at 23:15
  • It's not clear why you are making the leap from one kind of thing (path to a file on the machine where the code is running) to another entirely different kind of thing (URL) and assuming that they are interchangeable. Download the file from S3 to a temporary file... as your argument, use the path to that file (which is **now** an actual path to a file)... then delete the temporary file when you are done. – Michael - sqlbot Dec 27 '17 at 23:33
  • Thanks all for your help and feedback. This issue has been resolved. I utilized @stdunbar 's suggested solution. It's more clear to me how URLs and URIs are different & how ruby loads (or doesn't load) certain files. Here's the closed github issue for anyone else struggling with this problem: https://github.com/chiedolabs/stl_parser/issues/2 – chrisdmccoy Jan 03 '18 at 05:35

0 Answers0