# File\_field on widows

**URL:** <https://www.ruby-forum.com/t/file-field-on-widows/140573>\
**Category:** Rails\
**Created:** [June 16, 2008, 11:59am UTC](https://www.ruby-forum.com/t/file-field-on-widows/140573 "2008-06-16T11:59:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [June 16, 2008, 11:59am UTC](https://www.ruby-forum.com/t/file-field-on-widows/140573/1 "2008-06-16T11:59:47Z")

</div>

Hi to all,

i’m trying to upload a pdf or doc file on my server.  
My code works under linux, but now i move my app to a windows server and  
the documents (both pdf and doc) are not uplaoded correctly.

Here it’s my form code in the view:

\<%= form\_tag( { :action =\> ‘create’ }, :multipart =\> true ) -%\>

Cv  
\<%= file\_field 'nominee', 'cv' %\>

\<%= submit\_tag “Next” %\>

and this is my controller:

if(@nominee.cv != “”)  
file\_field=@nominee.cv rescue nil

```
 ext=file_field.original_filename.to_s.split('.')

File.open("#{$path}/public/cv/#{@nominee.id}.#{ext[1]}", "w") { |f|

```

f.write(file\_field.read)}  
@nominee.cv="/cv/#{@nominee[:id]}.#{ext[1]}"  
end

Can anybody help me???

Thanks in advance

Andrea

---

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [June 16, 2008, 12:08pm UTC](https://www.ruby-forum.com/t/file-field-on-widows/140573/2 "2008-06-16T12:08:33Z")

</div>

On 16 Jun 2008, at 10:59, Andrea C. wrote:

> 

Is $path what you think it is ? Where are things breaking down ?

Fred

---

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [June 16, 2008, 12:20pm UTC](https://www.ruby-forum.com/t/file-field-on-widows/140573/3 "2008-06-16T12:20:57Z")

</div>

On 16 Jun 2008, at 11:15, Andrea C. wrote:

> And it seems coorect also the uploading of the file, i mean that there  
> are no exception raised by Rails…  
> But after, when i try to dowload the file i can’t open it because it  
> is  
> corrupted…

windows might be one of those weird operating systems where ‘open in  
binary mode’ actually means something. (so pass wb as the file mode  
when creating)

Fred

---

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [June 16, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/file-field-on-widows/140573/4 "2008-06-16T12:25:04Z")

</div>

Frederick C. wrote:

> On 16 Jun 2008, at 11:15, Andrea C. wrote:
> 
> > And it seems coorect also the uploading of the file, i mean that there  
> > are no exception raised by Rails…  
> > But after, when i try to dowload the file i can’t open it because it  
> > is  
> > corrupted…
> 
> windows might be one of those weird operating systems where ‘open in  
> binary mode’ actually means something. (so pass wb as the file mode  
> when creating)
> 
> Fred

GREAT IT WORKS !!!

REALLY THANKS !!!

---

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [June 16, 2008, 12:15pm UTC](https://www.ruby-forum.com/t/file-field-on-widows/140573/5 "2008-06-16T12:15:56Z")

</div>

Frederick C. wrote:

> On 16 Jun 2008, at 10:59, Andrea C. wrote:
> 
> > 
> 
> Is $path what you think it is ? Where are things breaking down ?
> 
> Fred

The $path is correct the file is saved in the correct folder…  
And it seems coorect also the uploading of the file, i mean that there  
are no exception raised by Rails…  
But after, when i try to dowload the file i can’t open it because it is  
corrupted…

thanks Fred
