Hi, Has anyone experience file uploading in failed if file size less than 1kb for image. In this case png. I did try larger png and it was successful. It failed at the time copy the file from the uploaded directory path. (that 1kb did not get uploaded. as a result, only new file with size zero created). I did use "b" which set it to binary mode. f = File.new(@target_dir+file_name, "wb") FileUtils.copy uploaded_file.path, f.path Thank you in advance, Beta -- 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 -~----------~----~----~----~------~----~------~--~---
Havent experienced that, but have you tried attachment_fu plugin? On Jul 3, 4:52 am, Beta Beta <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > Has anyone experience file uploading in failed if file size less than > 1kb for image. In this case png. I did try larger png and it was > successful. > > It failed at the time copy the file from the uploaded directory path. > (that 1kb did not get uploaded. as a result, only new file with size > zero created). I did use "b" which set it to binary mode. > > f = File.new(@target_dir+file_name, "wb") > FileUtils.copy uploaded_file.path, f.path > > Thank you in advance, > Beta > -- > 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 -~----------~----~----~----~------~----~------~--~---
On Jul 2, 2008, at 11:52 PM, Beta Beta wrote:> Hi, > > Has anyone experience file uploading in failed if file size less than > 1kb for image. In this case png. I did try larger png and it was > successful. > > It failed at the time copy the file from the uploaded directory path. > (that 1kb did not get uploaded. as a result, only new file with size > zero created). I did use "b" which set it to binary mode. > > f = File.new(@target_dir+file_name, "wb") > FileUtils.copy uploaded_file.path, f.path > > Thank you in advance, > BetaSmall uploads are not put into a file, you might get a StringIO rather than a file. In either case you can call the .read method on the "file" that comes back from the form. If this doesn''t help you figure out your problem, post some code. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the feedback. (I did not use attachment fu because I just want simple upload without creating model or resizing image) starting from scratch, I am able to reproduce the problem (Rails 2.0.2) The problem in "uploaded_file.path" is nil if file less then 1kb To test it, try this file below (can use this if the attachment fail) http://www.google.com/images/x3.png ========== put this in views================ <p> <b>Upload file</b> <form action="/file_uploads/upload_action" id="upload_form" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file" /> <input type="submit" value="Upload" /> </form> </p> ============ put this in controller ==================== def upload_action uploaded_file = params[:uploaded_file] file_name = uploaded_file.original_filename @target_dir = "#{RAILS_ROOT}/public/assets/" unless File.directory?(@target_dir) FileUtils.mkdir_p(@target_dir) end f = File.new(@target_dir+file_name, "wb") FileUtils.copy uploaded_file.path, f.path end ======= put this one in controller , in case, if it ask for authenticity token: (this for testing purpose) ========protect_from_forgery :secret => ''webgen'', :only => :index ======================================================= Trying file read method as suggested by Rob Biedenharn===========================================================The reason why it failed because "uploaded_file.path" is nil ---------------- this below also failed---------- def upload_action3 # Do stuff with params[:uploaded_file] uploaded_file = params[:uploaded_file] file_name = uploaded_file.original_filename @target_dir = "#{RAILS_ROOT}/public/assets/" unless File.directory?(@target_dir) FileUtils.mkdir_p(@target_dir) end f = File.new(@target_dir+file_name, "wb") file_data = open(uploaded_file.path, "r") file_data.close end Attachments: http://www.ruby-forum.com/attachment/2303/x3.png -- 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 -~----------~----~----~----~------~----~------~--~---
If you want simple, look at the Paperclip plugin. It''s good to know how to do this yourself, but once you know you can, it''s better to use existing, tested code than to struggle with an error that''s impeding your progress (at least that''s my opinion.) On Thu, Jul 3, 2008 at 6:54 PM, Beta Beta <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Thanks for the feedback. (I did not use attachment fu because I just > want simple upload without creating model or resizing image) > > starting from scratch, I am able to reproduce the problem (Rails 2.0.2) > > The problem in "uploaded_file.path" is nil if file less then 1kb > > To test it, try this file below (can use this if the attachment fail) > http://www.google.com/images/x3.png > > ========== put this in views================> <p> <b>Upload file</b> > <form action="/file_uploads/upload_action" id="upload_form" > method="post" enctype="multipart/form-data"> > <input type="file" name="uploaded_file" /> > <input type="submit" value="Upload" /> > </form> > </p> > > > ============ put this in controller ====================> def upload_action > uploaded_file = params[:uploaded_file] > > file_name = uploaded_file.original_filename > @target_dir = "#{RAILS_ROOT}/public/assets/" > unless File.directory?(@target_dir) > FileUtils.mkdir_p(@target_dir) > end > f = File.new(@target_dir+file_name, "wb") > > FileUtils.copy uploaded_file.path, f.path > end > > ======= put this one in controller , in case, if it ask for authenticity > token: (this for testing purpose) ========> protect_from_forgery :secret => ''webgen'', :only => :index > > =====================================================> == Trying file read method as suggested by Rob Biedenharn========> ===================================================> The reason why it failed because "uploaded_file.path" is nil > > ---------------- this below also failed---------- > def upload_action3 > # Do stuff with params[:uploaded_file] > uploaded_file = params[:uploaded_file] > > file_name = uploaded_file.original_filename > @target_dir = "#{RAILS_ROOT}/public/assets/" > unless File.directory?(@target_dir) > FileUtils.mkdir_p(@target_dir) > end > f = File.new(@target_dir+file_name, "wb") > > file_data = open(uploaded_file.path, "r") > file_data.close > end > > > Attachments: > http://www.ruby-forum.com/attachment/2303/x3.png > > -- > 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 -~----------~----~----~----~------~----~------~--~---