Forum: Ruby on Rails saving the image

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.
775b1c27ba2dcbd4c26438b8a557f0a2?d=identicon&s=25 Bahadır Doğan (xyzt)
on 2007-07-26 08:48
Hello,

I try to prepare a upload page and here's my controller:

  def new
    if request.post?
        begin
          @file = params[:img]
          if @file.original_filename.length > 0
            filename = "/images/userimg/" + @file.original_filename
            File.open(filename, "wb")  { |f| f.write(@file.read) }
          end
        end
    end
  end

I want the file to be saved into the public/images/userimg folder. but i
get error at runtime: "No such file or directory -
/images/userimg/arrowd.gif"

what can i do for it?
E3513c4edd6810bb4b9914b58da2a2c3?d=identicon&s=25 Jamal Soueidan (jamal)
on 2007-07-26 09:04
Bahadır Doğan wrote:
> I want the file to be saved into the public/images/userimg folder. but i
> get error at runtime: "No such file or directory -
> /images/userimg/arrowd.gif"
>
> what can i do for it?

You check if you have folder /images/userimg :)
775b1c27ba2dcbd4c26438b8a557f0a2?d=identicon&s=25 Bahadır Doğan (xyzt)
on 2007-07-26 09:11
I have it: "public/images/userimg"

Do I need to get the real path of that folder?




Jamal Soueidan wrote:
> Bahadır Doğan wrote:
>> I want the file to be saved into the public/images/userimg folder. but i
>> get error at runtime: "No such file or directory -
>> /images/userimg/arrowd.gif"
>>
>> what can i do for it?
>
> You check if you have folder /images/userimg :)
1b975fda3889504d53a9726914d64fd2?d=identicon&s=25 Rusty Burchfield (Guest)
on 2007-07-26 09:52
(Received via mailing list)
On Jul 26, 3:11 am, "Bahadır Doğan" <rails-mailing-l...@andreas-s.net>
wrote:
> I have it: "public/images/userimg"
>
> Do I need to get the real path of that folder?

Try:
filename = "#{RAILS_ROOT}/public/images/userimg/" +
@file.original_filename

Be aware that this could be abused.  It might be possible for someone
to put ../ in the filename and do something malicious like add a
controller to your application or overwrite your log files.

~Rusty
775b1c27ba2dcbd4c26438b8a557f0a2?d=identicon&s=25 Bahadır Doğan (xyzt)
on 2007-07-26 11:46
yes,that's right:
       filename = "#{RAILS_ROOT}/public/images/userimg/" +
This topic is locked and can not be replied to.