Problem uploading files

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}) %>
File to Upload <%= file_field_tag “file” %>
<%= submit_tag %>
<%= end_form_tag %>

<% if defined? @file.original_filename %>
<%= debug @file %>

<%= @file.original_filename %>

<%= @file.path %>

<%= @file.content_type %>

<% 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 H. 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

Great, thank you!