# Where did my uploaded file go?

**URL:** <https://www.ruby-forum.com/t/where-did-my-uploaded-file-go/126179>\
**Category:** Rails\
**Created:** [January 16, 2008, 2:48am UTC](https://www.ruby-forum.com/t/where-did-my-uploaded-file-go/126179 "2008-01-16T02:48:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [January 16, 2008, 2:48am UTC](https://www.ruby-forum.com/t/where-did-my-uploaded-file-go/126179/1 "2008-01-16T02:48:22Z")

</div>

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/"removed\_email\_address@domain.invalid,  
: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](http://www.w3.org/2001/tag/doc/whenToUseGet.html))  
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/"removed\_email\_address@domain.invalid,  
: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!

---

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [January 16, 2008, 5:14am UTC](https://www.ruby-forum.com/t/where-did-my-uploaded-file-go/126179/2 "2008-01-16T05:14:09Z")

</div>

On Jan 15, 5:48 pm, Jojo M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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?

---

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [January 16, 2008, 6:40am UTC](https://www.ruby-forum.com/t/where-did-my-uploaded-file-go/126179/3 "2008-01-16T06:40:11Z")

</div>

Aaron C. wrote:

> On Jan 15, 5:48 pm, Jojo M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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

---

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [January 16, 2008, 7:45am UTC](https://www.ruby-forum.com/t/where-did-my-uploaded-file-go/126179/4 "2008-01-16T07:45:38Z")

</div>

On Jan 15, 9:40 pm, Jojo M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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](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.

---

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [January 17, 2008, 1:54am UTC](https://www.ruby-forum.com/t/where-did-my-uploaded-file-go/126179/5 "2008-01-17T01:54:04Z")

</div>

Aaron C. wrote:

> On Jan 15, 9:40 pm, Jojo M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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](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! 🙂

thanks guys!
