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:
- ENOENT, no such file or directory but file exists ()
- File Exists But Receiving ENOENT Error (I'm not using node and my server restarts everytime I deploy)
- 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.
- 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)
- 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
- 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).
- 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:
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?
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?
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.Is this because the my app doesn't have enough time to download the file from AWS before it tries to process the file?
CORS permissions in AWS?
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.