0

I am trying to get the full path from an image I am uploading with the rails file_field helper.

%h4 Upload Image
.col-sm-8
  =label_tag "Upload Image"
.col-sm-4  
  =form_tag(controller:"images", :html => {:multipart => true}) do
    =select("app", "app", ["#{Rails.env}_thing", "#{Rails.env}_otherthing"], {include_blank: true})
    =file_field :post, :image
    %button.btn.btn-primary.btn-block{:type => "submit"}
      ="Upload Image"

when it hits the controller action the params are:

{"utf8"=>"✓", "authenticity_token"=>"kVf52OKMdkQPte/jA99R33213123210WRklc2uMhGdM=", "app"=>{"app"=>"development_thing"}, "post"=>{"image"=>"picture.png"}, "html"=>{"multipart"=>"true"}, "action"=>"create", "controller"=>"images"}

What I really want though is the full path of that image file. How would I get that? So if I uploaded from my desktop it would be "/Users/bob/desktop/picture.png"

Thanks!

BC00
  • 1,589
  • 3
  • 29
  • 47
  • possible duplicate of [Full url for an image-path in Rails 3](http://stackoverflow.com/questions/5484809/full-url-for-an-image-path-in-rails-3) – Pavan Jun 10 '14 at 04:46

1 Answers1

0

You can't get the fullpath of file via input type 'file'. Browser will not allow it. Its a security feature in all modern browsers.

In chrome u will get

C:\fakepath\filename.ext

while in mozilla u only get filename

filename.ext

you can find lots of other question related to this. see

How to get the full path of the file from a file input

Full path from file input using jQuery

Community
  • 1
  • 1
Rahul Singh
  • 3,417
  • 2
  • 25
  • 32