# Sanitizing File Uploads

**URL:** <https://www.ruby-forum.com/t/sanitizing-file-uploads/142608>\
**Category:** Rails\
**Created:** [July 9, 2008, 5:28pm UTC](https://www.ruby-forum.com/t/sanitizing-file-uploads/142608 "2008-07-09T17:28:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [July 9, 2008, 5:28pm UTC](https://www.ruby-forum.com/t/sanitizing-file-uploads/142608/1 "2008-07-09T17:28:27Z")

</div>

The HTML element has a nice little browse feature  
that allows the user to browse for the file to be uploaded. However,  
it doesn’t seem to be quite so well endowed when it comes to  
determining the file name to be assigned to the uploaded file. In the  
particular case with which I am dealing, the directory into which the  
uploaded file is to be placed is pre-determined, so that’s not an  
issue. However, the name to be assigned to the uploaded file is  
another matter. At present, I am collecting that information in a  
separate element which I have labeled “Save As:”  
This seems to leave a bit to be desired. It would seem to me that by  
far the most common case would be where the user wants to have the  
uploaded file share the same name on the remote system that it has on  
the local system. Hence, I think the best thing would be to somehow  
pre-populate my text field for collecting the file name with that  
name. I have no idea how to do that. If anyone has any suggestions,  
I’d love to hear them. I would also be interested in hearing about  
other approaches that others are using to address this issue.

Thanks for any input.

```
     ... doug
```

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [July 9, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/sanitizing-file-uploads/142608/2 "2008-07-09T20:56:07Z")

</div>

doug wrote:

> …determining the file name to be assigned to the uploaded file. In the  
> particular case with which I am dealing, the directory into which the  
> uploaded file is to be placed is pre-determined…  
> … the user wants to have the  
> uploaded file share the same name on the remote system that it has on  
> the local system.  
> … doug

take a look at attachment\_fu,

> **[GitHub - technoweenie/attachment\_fu: Treat an ActiveRecord model as a file...](https://github.com/technoweenie/attachment_fu/tree/master)**
>
> master

it deals with a lot of the annoying stuff you’ll have to deal with.

and try to express your problems more concisely…  
the longer it is,  
the less people are going to read it,  
the less help you’ll get.

Take care.  
Matthew R…

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [July 10, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/sanitizing-file-uploads/142608/3 "2008-07-10T18:14:19Z")

</div>

> take a look at attachment\_fu,[GitHub - technoweenie/attachment\_fu: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.](http://github.com/technoweenie/attachment_fu/tree/master)
> 
> it deals with a lot of the annoying stuff you’ll have to deal with.

Thanks. I was hoping that there would be some sort of simple way to  
achieve the desired result. In fact, I sort of half-way expected it  
based on my perception that it was likely an issue that was commonly  
encountered. Apparently that’s not the case. I think I’ll just have  
to live with having the user enter the file name.

> and try to express your problems more concisely…  
> the longer it is,  
> the less people are going to read it,  
> the less help you’ll get.

Believe me, I understand the issue. On the one hand one can be  
criticized for being too verbose while on the other be criticized for  
being too brief and omitting relevant information. I agree with you  
that this post seemed a bit long. I wish that I had been able to  
shorten it; but, in my view there just wasn’t anything I could omit.

Thanks for the input.

```
      ... doug

```
