Hi everyone,
I''m having trouble uploading some files. I''ve set up a simple
action whose
view looks like:
<%= start_form_tag({:action => ''handle_file_test''},
{:multipart => true}) %>
<label for="file">File to Upload</label> <%=
file_field_tag "file" %>
<%= submit_tag %>
<%= end_form_tag %>
<% if defined? @file.original_filename %>
<%= debug @file %><br />
<%= @file.original_filename %><br />
<%= @file.path %><br />
<%= @file.content_type %><br />
<% end %>
The controller simply assigns params[:file] to @file.
For some of my files, "debug @file" reports that @file is a string.
For
these files, @file.path is empty. I can''t figure out any pattern for
why
this is happening. I upload one jpeg file, and the file shows up as a file.
I upload another, and the file shows up as a string.
Any ideas?
Thanks!
Daniel Higginbotham wrote:> For some of my files, "debug @file" reports that @file is a string. For > these files, @file.path is empty. I can''t figure out any pattern for > why > this is happening. I upload one jpeg file, and the file shows up as a > file. > I upload another, and the file shows up as a string. > > Any ideas?For uploads below a certain size (I forget how large, maybe a couple of k), you get back an IO object that can be read like a file, but is actually a string. I use somthing like: path = uploaded_file.local_path if path.blank? # it''s an IOString else # it''s a temp file end when I need to know the difference. --Al Evans -- Posted via http://www.ruby-forum.com/.
Great, thank you! -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Al Evans Sent: Wednesday, May 17, 2006 10:59 AM To: rails@lists.rubyonrails.org Subject: [Rails] Re: Problem uploading files Daniel Higginbotham wrote:> For some of my files, "debug @file" reports that @file is a string. For > these files, @file.path is empty. I can''t figure out any pattern for > why > this is happening. I upload one jpeg file, and the file shows up as a > file. > I upload another, and the file shows up as a string. > > Any ideas?For uploads below a certain size (I forget how large, maybe a couple of k), you get back an IO object that can be read like a file, but is actually a string. I use somthing like: path = uploaded_file.local_path if path.blank? # it''s an IOString else # it''s a temp file end when I need to know the difference. --Al Evans -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails