# How to persist file upload fields after a validation error

**URL:** <https://www.ruby-forum.com/t/how-to-persist-file-upload-fields-after-a-validation-error/170556>\
**Category:** Rails\
**Created:** [June 18, 2009, 9:43pm UTC](https://www.ruby-forum.com/t/how-to-persist-file-upload-fields-after-a-validation-error/170556 "2009-06-18T21:43:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marksbrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@marksbrain](https://www.ruby-forum.com/u/marksbrain)\
**Post date:** [June 18, 2009, 9:43pm UTC](https://www.ruby-forum.com/t/how-to-persist-file-upload-fields-after-a-validation-error/170556/1 "2009-06-18T21:43:31Z")

</div>

Hi all,

Is there an easy way to not lose the file field input from the user  
after a validation error? It pisses people off to have to choose  
their files again just because some other field didn’t pass a  
validation. I’ve googled this and just haven’t come up with much of  
anything.

Thanks.

---

<div class="post-metadata">

**Author:** ![marksbrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@marksbrain](https://www.ruby-forum.com/u/marksbrain)\
**Post date:** [June 19, 2009, 12:13am UTC](https://www.ruby-forum.com/t/how-to-persist-file-upload-fields-after-a-validation-error/170556/2 "2009-06-19T00:13:37Z")

</div>

I’m pretty sure you can’t do that for security reasons. Nothing to do  
with rails of course it’s just a browser thing.

Just imagine if you could pre-fill file upload fields!

Good luck!  
Tim

---

<div class="post-metadata">

**Author:** ![marksbrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@marksbrain](https://www.ruby-forum.com/u/marksbrain)\
**Post date:** [June 19, 2009, 8:25am UTC](https://www.ruby-forum.com/t/how-to-persist-file-upload-fields-after-a-validation-error/170556/3 "2009-06-19T08:25:32Z")

</div>

> On Jun 18, 12:19 pm, “Mark W.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi all,
> > 
> > Is there an easy way to not lose the file field input from the user  
> > after a validation error? It pisses people off to have to choose  
> > their files again just because some other field didn’t pass a  
> > validation. I’ve googled this and just haven’t come up with much of  
> > anything.
> > 
> > Thanks.

I save the file and store it’s location in a session variable, then  
you can get to the file again on resubmission.  
You will need a strategy to clean up orphaned files where the user has  
not re-submitted the form

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)

[http://MyMvelope.com](http://MyMvelope.com) - The SIMPLE way to manage your savings
