Forum: Ruby on Rails Problem uploading files

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
43ec5998360a0cc21b51afef1781e9c0?d=identicon&s=25 Daniel Higginbotham (danieldaniel)
on 2006-05-17 20:33
(Received via mailing list)
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!
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (al-evans)
on 2006-05-17 22:58
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
43ec5998360a0cc21b51afef1781e9c0?d=identicon&s=25 Daniel Higginbotham (danieldaniel)
on 2006-05-17 23:40
(Received via mailing list)
Great, thank you!
This topic is locked and can not be replied to.