I''m having a problem with small files getting corrupted on upload.
They''re fine when they''re created on the server, fine when
they''re received after being downloaded, but when I upload the same
files they''re corrupted. My upload code is included below. Maybe I
misplaced a comma or something. The only clues I''ve got is that the
corrupted file is larger than the original and Mongrel isn''t
''letting go''. I have to shut Mongrel down to delete the file.
I''d really appreciate any ideas/suggestions/pointers on what might be
going on here cause I''m definitely stumped.
TIA,
Bill
if params[:file_to_upload].instance_of?(Tempfile)
FileUtils.copy(params[:file_to_upload].local_path,
"#{RAILS_ROOT}/public/#{@filenametouse}")
else
File.open("#{RAILS_ROOT}/public/#{@filenametouse}","w"){|f|
f.write(params[:file_to_upload].read)
f.close}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
One more thing that might shed some light...
The files that are getting corrupted are pdf files that are about 7KB. They
contain a 1500 byte XML file attachment. The XML files can be uploaded without
getting corrupted. Not the PDFs.
Thanks,
Bill
----- Original Message -----
From: Bill Walton
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Sent: Tuesday, January 23, 2007 7:08 PM
Subject: [Rails] Small files getting corrupted on upload
I''m having a problem with small files getting corrupted on upload.
They''re fine when they''re created on the server, fine when
they''re received after being downloaded, but when I upload the same
files they''re corrupted. My upload code is included below. Maybe I
misplaced a comma or something. The only clues I''ve got is that the
corrupted file is larger than the original and Mongrel isn''t
''letting go''. I have to shut Mongrel down to delete the file.
I''d really appreciate any ideas/suggestions/pointers on what might be
going on here cause I''m definitely stumped.
TIA,
Bill
if params[:file_to_upload].instance_of?(Tempfile)
FileUtils.copy(params[:file_to_upload].local_path,
"#{RAILS_ROOT}/public/#{@filenametouse}")
else
File.open("#{RAILS_ROOT}/public/#{@filenametouse}","w"){|f|
f.write(params[:file_to_upload].read)
f.close}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Just marking the trail ...
''new'' fact: PDFs are binary.
hypothesis: it''s about handling binary files via String / Tempfile
I checked the FileUtils documentation and didn''t see anything
specifically addressing binary vs. ascii transfers. copy_entry does say it
''preserves file types''. Hoping that''s it. Check it
out first thing in the morning.
----- Original Message -----
From: Bill Walton
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Sent: Tuesday, January 23, 2007 7:29 PM
Subject: [Rails] Re: Small files getting corrupted on upload
One more thing that might shed some light...
The files that are getting corrupted are pdf files that are about 7KB. They
contain a 1500 byte XML file attachment. The XML files can be uploaded without
getting corrupted. Not the PDFs.
Thanks,
Bill
----- Original Message -----
From: Bill Walton
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Sent: Tuesday, January 23, 2007 7:08 PM
Subject: [Rails] Small files getting corrupted on upload
I''m having a problem with small files getting corrupted on upload.
They''re fine when they''re created on the server, fine when
they''re received after being downloaded, but when I upload the same
files they''re corrupted. My upload code is included below. Maybe I
misplaced a comma or something. The only clues I''ve got is that the
corrupted file is larger than the original and Mongrel isn''t
''letting go''. I have to shut Mongrel down to delete the file.
I''d really appreciate any ideas/suggestions/pointers on what might be
going on here cause I''m definitely stumped.
TIA,
Bill
if params[:file_to_upload].instance_of?(Tempfile)
FileUtils.copy(params[:file_to_upload].local_path,
"#{RAILS_ROOT}/public/#{@filenametouse}")
else
File.open("#{RAILS_ROOT}/public/#{@filenametouse}","w"){|f|
f.write(params[:file_to_upload].read)
f.close}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Bill-
Are you doing this on windows? If so you need to set the binary flag
when you open a file for writing.
File.open("#{RAILS_ROOT}/public/#{@filenametouse}","wb"){|f|
f.write(params[:file_to_upload].read)
f.close}
note the "wb" as the second arg to File.open
-Ezra
On Jan 23, 2007, at 7:28 PM, Bill Walton wrote:
> Just marking the trail ...
>
> ''new'' fact: PDFs are binary.
>
> hypothesis: it''s about handling binary files via String / Tempfile
>
> I checked the FileUtils documentation and didn''t see anything
> specifically addressing binary vs. ascii transfers. copy_entry
> does say it ''preserves file types''. Hoping
that''s it. Check it
> out first thing in the morning.
> ----- Original Message -----
> From: Bill Walton
> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Sent: Tuesday, January 23, 2007 7:29 PM
> Subject: [Rails] Re: Small files getting corrupted on upload
>
> One more thing that might shed some light...
>
> The files that are getting corrupted are pdf files that are about
> 7KB. They contain a 1500 byte XML file attachment. The XML files
> can be uploaded without getting corrupted. Not the PDFs.
>
> Thanks,
> Bill
> ----- Original Message -----
> From: Bill Walton
> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Sent: Tuesday, January 23, 2007 7:08 PM
> Subject: [Rails] Small files getting corrupted on upload
>
> I''m having a problem with small files getting corrupted on upload.
> They''re fine when they''re created on the server, fine
when they''re
> received after being downloaded, but when I upload the same files
> they''re corrupted. My upload code is included below. Maybe I
> misplaced a comma or something. The only clues I''ve got is that
> the corrupted file is larger than the original and Mongrel isn''t
> ''letting go''. I have to shut Mongrel down to delete the
file. I''d
> really appreciate any ideas/suggestions/pointers on what might be
> going on here cause I''m definitely stumped.
>
> TIA,
> Bill
>
> if params[:file_to_upload].instance_of?(Tempfile)
> FileUtils.copy(params[:file_to_upload].local_path, "#
> {RAILS_ROOT}/public/#{@filenametouse}")
> else
>
File.open("#{RAILS_ROOT}/public/#{@filenametouse}","w"){|f|
>
> f.write(params[:file_to_upload].read)
>
> f.close}
> >
>
-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- ez-NLltGlunAUd/unjJdyJNww@public.gmane.org
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ezra, Yes, I''m doing on Windows. THANK YOU! Best regards, Bill ----- Original Message ----- From: "Ezra Zygmuntowicz" <ezmobius-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Tuesday, January 23, 2007 10:14 PM Subject: [Rails] Re: Small files getting corrupted on upload> > > > Bill- > > Are you doing this on windows? If so you need to set the binary flag > when you open a file for writing. > > File.open("#{RAILS_ROOT}/public/#{@filenametouse}","wb"){|f| > > f.write(params[:file_to_upload].read) > > f.close} > > > note the "wb" as the second arg to File.open > > -Ezra > > On Jan 23, 2007, at 7:28 PM, Bill Walton wrote: > >> Just marking the trail ... >> >> ''new'' fact: PDFs are binary. >> >> hypothesis: it''s about handling binary files via String / Tempfile >> >> I checked the FileUtils documentation and didn''t see anything >> specifically addressing binary vs. ascii transfers. copy_entry >> does say it ''preserves file types''. Hoping that''s it. Check it >> out first thing in the morning. >> ----- Original Message ----- >> From: Bill Walton >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> Sent: Tuesday, January 23, 2007 7:29 PM >> Subject: [Rails] Re: Small files getting corrupted on upload >> >> One more thing that might shed some light... >> >> The files that are getting corrupted are pdf files that are about >> 7KB. They contain a 1500 byte XML file attachment. The XML files >> can be uploaded without getting corrupted. Not the PDFs. >> >> Thanks, >> Bill >> ----- Original Message ----- >> From: Bill Walton >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> Sent: Tuesday, January 23, 2007 7:08 PM >> Subject: [Rails] Small files getting corrupted on upload >> >> I''m having a problem with small files getting corrupted on upload. >> They''re fine when they''re created on the server, fine when they''re >> received after being downloaded, but when I upload the same files >> they''re corrupted. My upload code is included below. Maybe I >> misplaced a comma or something. The only clues I''ve got is that >> the corrupted file is larger than the original and Mongrel isn''t >> ''letting go''. I have to shut Mongrel down to delete the file. I''d >> really appreciate any ideas/suggestions/pointers on what might be >> going on here cause I''m definitely stumped. >> >> TIA, >> Bill >> >> if params[:file_to_upload].instance_of?(Tempfile) >> FileUtils.copy(params[:file_to_upload].local_path, "# >> {RAILS_ROOT}/public/#{@filenametouse}") >> else >> File.open("#{RAILS_ROOT}/public/#{@filenametouse}","w"){|f| >> >> f.write(params[:file_to_upload].read) >> >> f.close} >> > >> > > -- Ezra Zygmuntowicz > -- Lead Rails Evangelist > -- ez-NLltGlunAUd/unjJdyJNww@public.gmane.org > -- Engine Yard, Serious Rails Hosting > -- (866) 518-YARD (9273) > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---