I am using the following line of code in an action to provide a file upload capability. File.open(params[:upload_directory]+''/''+''test1'',''wb''){|f| f.write(params[:file2upload].read)} Admittedly, I''m not real clear on exactly how the above line works; but, it does work. I''m wondering if there is any way I can get at the original file name (i.e., the name of the file on the system from which the file is being uploaded) so that I could substitute it for ''test1'' and thereby preserve the original file name. Any suggestions would be appreciated. Thanks. ... doug -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Try this: File.open(File.join(params[:upload_directory], params[:file2upload].original_filename),''wb''){ |f| f.write(params[:file2upload].read) } Jamey On Mon, Mar 8, 2010 at 9:56 PM, doug <ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using the following line of code in an action to provide a file > upload capability. > > File.open(params[:upload_directory]+''/''+''test1'',''wb''){|f| > f.write(params[:file2upload].read)} > > Admittedly, I''m not real clear on exactly how the above line works; > but, it does work. I''m wondering if there is any way I can get at the > original file name (i.e., the name of the file on the system from > which the file is being uploaded) so that I could substitute it for > ''test1'' and thereby preserve the original file name. > > Any suggestions would be appreciated. Thanks. > > ... doug > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
> Try this: > > File.open(File.join(params[:upload_directory], > params[:file2upload].original_filename),''wb''){ |f| > f.write(params[:file2upload].read) }Yes; but, as I understand your suggestion, that would require me to pass the original filename as a parameter. What I''m trying to find out is whether the original filename is somehow available for use as a part of the file upload mechanism without my having to pass it as a parameter. If it turns out that it''s not available within the file upload mechanism; then, I can pass it. It''s just that I don''t want to go that route if there is an easier way. Thanks for the input. ... doug -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
That''s what I''m trying to tell you. If you are using a multipart form to upload your file, then the #original_filename attribute should be available on the uploaded file object. Jamey On Tue, Mar 9, 2010 at 1:46 PM, doug <ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> Try this: >> >> File.open(File.join(params[:upload_directory], >> params[:file2upload].original_filename),''wb''){ |f| >> f.write(params[:file2upload].read) } > > Yes; but, as I understand your suggestion, that would require me to > pass the original filename as a parameter. What I''m trying to find > out is whether the original filename is somehow available for use as a > part of the file upload mechanism without my having to pass it as a > parameter. If it turns out that it''s not available within the file > upload mechanism; then, I can pass it. It''s just that I don''t want to > go that route if there is an easier way. > > Thanks for the input. > > ... doug > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
> That''s what I''m trying to tell you. If you are using a multipart form > to upload your file, then the #original_filename attribute should be > available on the uploaded file object.Got it! I''m an idiot! Thanks a batch. ... doug -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.