Paperclip saving/retrieving files above public/

Hello all,

I'm quite baffled/agitated by this. I'm using paperclip to allow upload
of images to my application. This is working fine, it's saving the the
images exactly where its supposed to and it's saving the image objects
as its supposed to.

The problem is that I can't display these images in the browser. I've
had this issue in a couple other applications I've made and just got
around it by having paperclip save to the public folder and pull from
there to display the desired image. But I feel as though I should get
this sorted out.

So here goes:

My image model (paperclip)

Unless you've got an ImagesController (not shown here), the :url
argument you're using is the problem. Files in the public directory
are served as-is, so yours will be in /
uploaded/:attachable_type/:attachable_id/:id_:style.:extension

--Matt Jones

Ok that makes sense. Thank you.

Though I'm still not getting this to work. Where do I go from here?

I created the images_controller and created routes for them. I looked
into this and saw some one else doing this in their controller to handle
'documents' (pdfs, jpgs, pngs, etc)

Anyone have anything they can add? Any help at this point would be
appreciated.

Does anyone have any ideas on this?

Please I'm still desperate for an answer

why don't you use the standard and simple way ?

this is what I have in my app :

model Product
has_attached_file :product_image, :styles => { :left =>
'225>x238>', :big => '600x600>'}

# product_image_file_name :string(255)
# product_image_content_type :string(255)
# product_image_file_size :integer(4)
# product_image_updated_at :date time

uploads are saved in /public/system/product_images/:id/big/* /public/
system/product_images/:id/left/* /public/system/product_images/:id/
original/*

I display the pictures with the following url ::
@product.product_image.url(:left) @product.product_image.url(:big)
@product.product_image.url

Try adding "public" to your path:
:path => ":rails_root/public/
uploaded/:attachable_type/:attachable_id/:id_:style.:extension "

Then you can just link directly to it:
<img src="/uploaded/:attachable_type/:id/:id_:style.:extension" />

For those of you who recommend the public folder, the only problem with
that for me and I'm sure others is that we may want some uploads to be
private, and prevent users from simply browsing the public directory on
our webapps to look at every-bodies uploads. By using our own custom
folders we can prevent this with very little code.

By correctly configuring your server, you can prevent this without any code. “Options -Indexes” on Apache, “autoindex off” in nginx.

–Matt Jones