# Original filename doesn't display in file\_field

**URL:** <https://www.ruby-forum.com/t/original-filename-doesnt-display-in-file-field/53045>\
**Category:** Rails\
**Created:** [November 17, 2005, 11:20am UTC](https://www.ruby-forum.com/t/original-filename-doesnt-display-in-file-field/53045 "2005-11-17T11:20:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 17, 2005, 11:20am UTC](https://www.ruby-forum.com/t/original-filename-doesnt-display-in-file-field/53045/1 "2005-11-17T11:20:44Z")

</div>

In my item upload view I have:

\<%= file\_field ‘item’, ‘file’ %\>

and in my Item model:

def file  
@file  
#@file.original\_filename # ← also tried this  
end

def file=(file)  
@file=file  
end

And if the upload bails because of errors (and renders the same page),  
all other fields  
(text\_field, text\_area, etc.) retain their inputted values, but the file  
field is blank. Any idea  
what the problem is?

I’m using this tutorial as a guide:  
[http://manuals.rubyonrails.com/read/chapter/79](http://manuals.rubyonrails.com/read/chapter/79)

thanks  
csn

* * *

Yahoo! FareChase: Search multiple travel sites in one click.  
[http://farechase.yahoo.com](http://farechase.yahoo.com)

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [November 17, 2005, 11:44am UTC](https://www.ruby-forum.com/t/original-filename-doesnt-display-in-file-field/53045/2 "2005-11-17T11:44:54Z")

</div>

Have a look at the approach taken by Sebastian K. in his  
file\_column plugin [1]. When a file upload form had errors and needs  
to be re-displayed, he uses a hidden field to reference the file that  
had been previously uploaded to the server.

The ‘value’ attribute of a form “file” input represents only the name  
of the file, not the file’s content [2] [3]. My guess is that not all  
browsers will actually upload a file when you haven’t explicitly  
selected it with the file input’s browse dialog (?). It does work in  
Firefox though.

Gerret

[1] [http://www.kanthak.net/opensource/file\_column/](http://www.kanthak.net/opensource/file_column/)  
[2] [http://www.cs.tut.fi/~jkorpela/forms/file.html](http://www.cs.tut.fi/~jkorpela/forms/file.html)  
[3] [RFC 1867 - Form-based File Upload in HTML (RFC1867)](http://www.faqs.org/rfcs/rfc1867.html)
