# Upload File Corruption Error

**URL:** <https://www.ruby-forum.com/t/upload-file-corruption-error/143029>\
**Category:** Rails\
**Created:** [July 14, 2008, 5:03pm UTC](https://www.ruby-forum.com/t/upload-file-corruption-error/143029 "2008-07-14T17:03:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@Marra](https://www.ruby-forum.com/u/Marra)\
**Post date:** [July 14, 2008, 5:03pm UTC](https://www.ruby-forum.com/t/upload-file-corruption-error/143029/1 "2008-07-14T17:03:30Z")

</div>

Hello All,

I’ve been reading a lot of blogs/tutorials on how to go about  
uploading files to a server via a form in my application - they all  
pointed me in the direction that “File.open(self.path, “wb”) { |f|  
f.write(@uploaded\_file.read) }” is what will write the file to the new  
location on the server.

I’ve tried this over and over again an each time the file moves over  
to the new location on my computer but the file becomes corrupt. Files  
don’t contain the data it should and pictures don’t open.

I’m working on trying to use attachment\_fu and other plugins that  
people have been raving about but in the mean time I thought to throw  
this problem at you guys and see if anyone else came across this issue  
and how they may have resolved it.

(In case you are curious I need to be able to upload files like docs  
pdfs images zips to the server - the database will contain the  
filename and location.)

So, has anyone had their files corrupt in their attempts to upload  
files to their server?

Marra

---

<div class="post-metadata">

**Author:** ![Marra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@Marra](https://www.ruby-forum.com/u/Marra)\
**Post date:** [July 14, 2008, 5:40pm UTC](https://www.ruby-forum.com/t/upload-file-corruption-error/143029/2 "2008-07-14T17:40:07Z")

</div>

are you using Windows? such problems are common in this  
OS. for reading a file, for example, you must use  
an ‘rb’ parameter (e.g. “File.open(path, ‘rb’)”), so  
perhaps there is some Windows requirement that you  
are missing.

---

<div class="post-metadata">

**Author:** ![Marra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@Marra](https://www.ruby-forum.com/u/Marra)\
**Post date:** [July 14, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/upload-file-corruption-error/143029/3 "2008-07-14T17:51:24Z")

</div>

Thank you for replying!

I am working on a Macintosh. It gives me an error

No such file or directory - /Users/mariam/Documents/intervu/public/  
data/artifacts/0714081149-Picture 1.png

when I replace wb with rb. I’m going to research uploading files on  
macs instead.

Marra

On Jul 14, 11:40 am, PP Junty [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
