I''ve made a file upload for word-files. It works fine. I also have a send_file for getting it from the server. But there must be something wrong with the file upload. When downloading it I can''t open the file. The same if I fetch it via ftp, so it must be something about the upload and doc type. Any ideas? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Pål, Pål Bergström wrote:> I''ve made a file upload for word-files. It works fine. > I also have a send_file for getting it from the server. > But there must be something wrong with the file upload. > When downloading it I can''t open the file. The same if > I fetch it via ftp, so it must be something about the upload > and doc type. Any ideas?I assume you''re talking about MS-Word? If so, are treating them as binary? IIRC, you have to. HTH, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > I assume you''re talking about MS-Word? If so, are treating them as > binary? > IIRC, you have to. > > HTH, > BillYes it''s MS-Word. How do I make it binary? I use this to create the file on the server: File.open("#{RAILS_ROOT}/public/documents/#{filename}", "w+") { |f| f.write(thefile.read) } In the db I add the file name in a varchar-field. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
File.open("blah", "wb") Only on a windows platform though. http://www.ruby-doc.org/core/classes/IO.html On Jul 18, 2:42 pm, Pål Bergström <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I assume you''re talking about MS-Word? If so, are treating them as > > binary? > > IIRC, you have to. > > > HTH, > > Bill > > Yes it''s MS-Word. How do I make it binary? > > I use this to create the file on the server: > > File.open("#{RAILS_ROOT}/public/documents/#{filename}", "w+") { |f| > f.write(thefile.read) } > > In the db I add the file name in a varchar-field. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
julian wrote:> File.open("blah", "wb") > > Only on a windows platform though. > > http://www.ruby-doc.org/core/classes/IO.html > > On Jul 18, 2:42�pm, P�l Bergstr�m <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Then "w+" should be ok I guess. What about this { |f| f.write(thefile.read) } Is there something I do wrong there, that somehow makes it into something different than MS-Word? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Pål, Pål Bergström wrote:> julian wrote: > > File.open("blah", "wb") > > > > Only on a windows platform though. > > > > http://www.ruby-doc.org/core/classes/IO.html > > > Then "w+" should be ok I guess. What about thisDid you try setting it to "wb"? I''ve never been clear about whether that "Windows-only" comment in the documentation referred to the server or the client. At any rate, I know from experience that using it doesn''t hurt because I develop on Windows and deploy to Linux and had to use it to handle PDF''s.> > { |f| f.write(thefile.read) } > > Is there something I do wrong there, that somehow > makes it into something different than MS-Word?A couple of other thing occured to me that might be causing you problems. One is whether or not Word files have to be treated as multipart. The second is the difference between IO streams and tempfiles. Which one you get depends on the size of the file being uploaded and you have to handle them differently. Here''s a snippet from some working code that uploads PDF files... In the view: <%= start_form_tag({:controller => ''transfer'', :action => ''read_in''}, :method => "post", :multipart => true) %> <div class=''Entryline''> <label>File to Upload: </label> <%= file_field_tag "file_to_upload", :size => 50 %> </div> <div> <%= submit_tag value="Import file", :class => ''submit-btn'', :disable_with => "Please Wait" %> </div> <%= end_form_tag %> In the read_in method in the controller: if params[:file_to_upload].instance_of?(Tempfile) FileUtils.copy(params[:file_to_upload].local_path, "#{RAILS_ROOT}/private/#{@filenametouse}") else File.open("#{RAILS_ROOT}/private/#{@filenametouse}","wb"){|f| f.write(params[:file_to_upload].read) f.close} end HTH, Bill --~--~---------~--~----~------------~-------~--~----~ 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 Walton wrote:> if params[:file_to_upload].instance_of?(Tempfile) > FileUtils.copy(params[:file_to_upload].local_path, > "#{RAILS_ROOT}/private/#{@filenametouse}") > else > File.open("#{RAILS_ROOT}/private/#{@filenametouse}","wb"){|f| > f.write(params[:file_to_upload].read) > f.close} > end > > HTH, > BillThank you. I''ll give it a try. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pål Bergström wrote:> Bill Walton wrote: > > >> if params[:file_to_upload].instance_of?(Tempfile) >> FileUtils.copy(params[:file_to_upload].local_path, >> "#{RAILS_ROOT}/private/#{@filenametouse}") >> else >> File.open("#{RAILS_ROOT}/private/#{@filenametouse}","wb"){|f| >> f.write(params[:file_to_upload].read) >> f.close} >> end >> >> HTH, >> Bill > > Thank you. I''ll give it a try.Didn''t work. The only diff is that I use w+ instead because it''s a Mac OS server running Litespeed. Hmm. Strange. Same problem with .rtf-files. Can it be something about the encoding? If nothing else I''ll have to solve it with php, but that would be very disappointing. Sourly it must be possible with Ruby / Rails to send what ever file you want to the server. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry, but how hard can it be? Can Rails handle a file upload or not? I mean other than images and make them accessible by download. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sat, Jul 19, 2008 at 12:57 PM, Pål Bergström <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Sorry, but how hard can it be? Can Rails handle a file upload or not? I > mean other than images and make them accessible by download.Not hard at all, apparently. :-) Since I''d never done this in Rails and knew I''ll need it soon, I just created a new project (Rails 2.1), installed the attachment_fu plugin and, following this handy-dandy tutorial: <http://clarkware.com/cgi/blosxom/2007/02/24#FileUploadFu> :: created an upload tester in about 15 minutes. I uploaded a Word (97, .doc) file and a PDF file. And then opened the stored files successfully. So I think it''s a given that Rails (or at least attachment_fu) can handle whatever binary file type you have. :-) Have you compared checksums of the two versions of the file you''re having trouble with? Are you *sure* you downloaded it using FTP *in binary mode*? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hassan Schroeder wrote:> On Sat, Jul 19, 2008 at 12:57 PM,> I uploaded a Word (97, .doc) file and a PDF file. And then opened the > stored files successfully. > > So I think it''s a given that Rails (or at least attachment_fu) can > handle > whatever binary file type you have. :-) > > Have you compared checksums of the two versions of the file you''re > having trouble with? Are you *sure* you downloaded it using FTP > *in binary mode*? > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.orgIf attachment_fu works then it should work. I would like to learn it myself without any plugin. I believe I will learn more from that, and to be more free to what I want to do. It''s binary. The problem is uploading. No problem downloading a "good" file that''s been uploaded by ftp. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sat, Jul 19, 2008 at 3:00 PM, Pål Bergström <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> The problem is uploading.OK, so there''s something wrong with your upload code -- you might be able to get some insight by looking at how attachment_fu does it, but whatever. As I said, comparing checksums would be my first move. Maybe try a couple of small text files, too, just for comparison. Good luck, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hassan Schroeder wrote:> On Sat, Jul 19, 2008 at 3:00 PM, > P�l Bergstr�m<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> The problem is uploading. > > OK, so there''s something wrong with your upload code -- you might > be able to get some insight by looking at how attachment_fu does it, > but whatever. > > As I said, comparing checksums would be my first move. Maybe try a > couple of small text files, too, just for comparison. > > Good luck, > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.orgGot the same idea. I''m looking at it now. Thanks for the help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
>> if params[:file_to_upload].instance_of?(Tempfile) >> FileUtils.copy(params[:file_to_upload].local_path, >> "#{RAILS_ROOT}/private/#{@filenametouse}") >> else >> File.open("#{RAILS_ROOT}/private/#{@filenametouse}","wb"){|f| >> f.write(params[:file_to_upload].read) >> f.close}Can''t get .local_path to work. Is that a rails method or something from Ruby? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---