Where did my uploaded file go?

Hi, i have made a file uploading function on my application, the thing
is

i want to allow my users to download the file (can be pdf, doc, img,
etc)

so in my file upload controller:

def download
@photo = Photo.find(params[:id])
send_file("#{RAILS_ROOT}/public/"[email protected],
:filename => @photo.filename,
:type => @photo.content_type,
:disposition => ‘attachment’)
end

this works perfectly fine, BUT only if the file actually exists in
…/public/…

i noticed that when i try to upload a file using the app,

it doesn’t automatically store it into the public folder.
if i manually copy paste the file into the public folder, the download
works fine.

this is my controller, (notice that the new & create methods doesn’t say
anything about storing the uploaded files into the public folder)

class PhotoAdminController < ApplicationController
def index
list
render :action => ‘list’
end

GETs should be safe (see

URIs, Addressability, and the use of HTTP GET and POST)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }

def list
@photo_pages, @photos = paginate :photos, :per_page => 10
end

def show
@photo = Photo.find(params[:id])
end

def new
@photo = Photo.new
end

def create
@photo = Photo.new(params[:photo])
if @photo.save
flash[:notice] = ‘Photo was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

def edit
@photo = Photo.find(params[:id])
end

def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(params[:photo])
flash[:notice] = ‘Photo was successfully updated.’
redirect_to :action => ‘show’, :id => @photo
else
render :action => ‘edit’
end
end

def destroy
Photo.find(params[:id]).destroy
redirect_to :action => ‘list’
end

def download
@photo = Photo.find(params[:id])
send_file("#{RAILS_ROOT}/public/images/"[email protected],
:filename => @photo.filename,
:type => @photo.content_type,
:disposition => ‘attachment’)
end
end

can someone teach me how to code my app to store the uploaded file into
the public folder?

thank you very much in advance!

On Jan 15, 5:48 pm, Jojo M. [email protected]
wrote:

can someone teach me how to code my app to store the uploaded file into
the public folder?

I suggest you use the attachment_fu plugin. It works very well and
will give you the option of storing your files in the database, file
system or using Amazon S3. You could certainly write similar code
yourself, but why re-invent the wheel?

Aaron C. wrote:

On Jan 15, 5:48 pm, Jojo M. [email protected]
wrote:

can someone teach me how to code my app to store the uploaded file into
the public folder?

I suggest you use the attachment_fu plugin. It works very well and
will give you the option of storing your files in the database, file
system or using Amazon S3. You could certainly write similar code
yourself, but why re-invent the wheel?

i’ve looked through the attachment_fu plugin, but i didn’t seem to see
any where that states storing files in the database

On Jan 15, 9:40 pm, Jojo M. [email protected]
wrote:

i’ve looked through the attachment_fu plugin, but i didn’t seem to see
any where that states storing files in the database

Read the section called ‘attachment_fu migrations’ in this document:
http://svn.techno-weenie.net/projects/plugins/attachment_fu/README.
DB storage is the default, although you probably want to store images
in the file system instread.

Aaron C. wrote:

On Jan 15, 9:40 pm, Jojo M. [email protected]
wrote:

i’ve looked through the attachment_fu plugin, but i didn’t seem to see
any where that states storing files in the database

Read the section called ‘attachment_fu migrations’ in this document:
http://svn.techno-weenie.net/projects/plugins/attachment_fu/README.
DB storage is the default, although you probably want to store images
in the file system instread.

oh i see it now! :slight_smile:

thanks guys!