Forum: Ruby on Rails File Upload Problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nick (Guest)
on 2006-04-10 21:42

following the instructions at
http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles, I am able
to upload to an explicit and existing directory (i.e.
c:\ror\app\public\images\photo.jpg).  However, when I try to upload to
a folder that does not exist, say,
c:\ror\app\public\image\newfolder\photo.jpg, I get the following error:

Errno::ENOENT in Images#create

No such file or directory -
C:/Apache/Apache2/htdocs/ror/ae/public/../config/../public/images/newfolder/testimage.jpg

RAILS_ROOT: C:/Apache/Apache2/htdocs/ror/ae/public/../config/..
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/models/post.rb:3:in `initialize'
#{RAILS_ROOT}/app/models/post.rb:3:in `open'
#{RAILS_ROOT}/app/models/post.rb:3:in `save'
#{RAILS_ROOT}/app/controllers/images_controller.rb:24:in `create'

Initially, I thought it is a permissions issue on the folder not
allowing the
web user to create a directory, but I can't find a place in the apache
config or
.htaccess files to specify the correct permissions.

Here's my environment:

Ruby version	1.8.2 (i386-mswin32)
RubyGems version	0.8.11
Rails version	1.1.0
Active Record version	1.14.0
Action Pack version	1.12.0
Action Web Service version	1.1.0
Action Mailer version	1.2.0
Active Support version	1.3.0
Application root	C:/Apache/Apache2/htdocs/ror/ae
Environment	development
Database adapter	mysql
Apache 2.0.55 w/ fcgi

Thanks for any help you may offer.
Steve K. (Guest)
on 2006-04-10 21:46
I don't see anything in the Wiki page you cite that handles checking to
see if the directory exists and creating it if it doesn't. You would
need to write code to do that.

However, you really might want to look at the file_column plugin.


Nick wrote:
>
>
> following the instructions at
> http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles, I am able
> to upload to an explicit and existing directory (i.e.
> c:\ror\app\public\images\photo.jpg).  However, when I try to upload to
> a folder that does not exist, say,
> c:\ror\app\public\image\newfolder\photo.jpg, I get the following error:
>
> Errno::ENOENT in Images#create
>
> No such file or directory -
> 
C:/Apache/Apache2/htdocs/ror/ae/public/../config/../public/images/newfolder/testimage.jpg
>
> RAILS_ROOT: C:/Apache/Apache2/htdocs/ror/ae/public/../config/..
> Application Trace | Framework Trace | Full Trace
>
> #{RAILS_ROOT}/app/models/post.rb:3:in `initialize'
> #{RAILS_ROOT}/app/models/post.rb:3:in `open'
> #{RAILS_ROOT}/app/models/post.rb:3:in `save'
> #{RAILS_ROOT}/app/controllers/images_controller.rb:24:in `create'
>
> Initially, I thought it is a permissions issue on the folder not
> allowing the
> web user to create a directory, but I can't find a place in the apache
> config or
> .htaccess files to specify the correct permissions.
>
> Here's my environment:
>
> Ruby version	1.8.2 (i386-mswin32)
> RubyGems version	0.8.11
> Rails version	1.1.0
> Active Record version	1.14.0
> Action Pack version	1.12.0
> Action Web Service version	1.1.0
> Action Mailer version	1.2.0
> Active Support version	1.3.0
> Application root	C:/Apache/Apache2/htdocs/ror/ae
> Environment	development
> Database adapter	mysql
> Apache 2.0.55 w/ fcgi
>
> Thanks for any help you may offer.
James M. (Guest)
on 2006-04-10 22:55
(Received via mailing list)
Nick <nicholas.shiffert@...> writes:

>
> No such file or directory -
>
C:/Apache/Apache2/htdocs/ror/ae/public/../config/../public/images/
> web user to create a directory, but I can't find a place in the apache
> Action Web Service version	1.1.0
> Action Mailer version	1.2.0
> Active Support version	1.3.0
> Application root	C:/Apache/Apache2/htdocs/ror/ae
> Environment	development
> Database adapter	mysql
> Apache 2.0.55 w/ fcgi
>
> Thanks for any help you may offer.
>


Nick,

I would use file_column as it does so much of the heavy
lifting for you.

http://www.kanthak.net/opensource/file_column/
http://wiki.rubyonrails.org/rails/pages/HowToUseFileColumn

I notice you are on ruby 1.8.2 you should be on 1.8.4 for
rails 1.1.0. If you use file_column with 1.8.4 tho you will
have to run without Rmagick until they come up with a 1.8.4
compatible version. I would also go to rails 1.1.1.

back on topic, file_column works a treat!

James
Marek (Guest)
on 2006-05-08 18:27
I have a similar error, but i dont want to use file_column right now,
cause i'm in a DBI environment. So, how can i just create a subdirectory
in public/images?

Nick wrote:
>
>
> following the instructions at
> http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles, I am able
> to upload to an explicit and existing directory (i.e.
> c:\ror\app\public\images\photo.jpg).  However, when I try to upload to
> a folder that does not exist, say,
> c:\ror\app\public\image\newfolder\photo.jpg, I get the following error:
>
> Errno::ENOENT in Images#create
>
> No such file or directory -
> 
C:/Apache/Apache2/htdocs/ror/ae/public/../config/../public/images/newfolder/testimage.jpg
This topic is locked and can not be replied to.