Forum: Ruby on Rails Multiple file uploads - only one file object gets posted

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.
Wes G. (Guest)
on 2006-04-03 21:01
All,

Trying to upload multiple files.

Form:

<% index = 0
   for @image in images do %>
  <TR>
    <TD>
      <%= @image.path.split('/').last[0..39] %>:
      <% if ((! @image.path.nil?) && (@image.path.length > 40)) %>
         <%= h("...") %>
      <% end %>
    </TD>
    <TD>
      <%= file_field('image', 'fileobj', :index => index) %>
    </TD>
  </TR>

<%   index += 1
   end
%>

I browse for 3 of the many files, and submit the form:

When I look at params in the controller, I see:

"0"=>{"fileobj"=>#<File:C:/DOCUME~1/WESLEY~1/LOCALS~1/Temp/CGI2444.0>}

but the other two indices for which I expected File objects only show
StringIO objects.

Why do I not see 3 files objects in my parameter array when I
"Browse..." to three files and submit my form?

Thanks,
Wes
Markus Piff (Guest)
on 2006-04-11 01:59
(Received via mailing list)
Hi,

this isn't a real problem, which you are experiencing here.
Due to this CGI stuff, a large "File" gets mapped in a File object,
whereas
small files are being represented by StringIO objects. The reason, why
it is
done in this way may be performance, but I'm not really sure about this.

To make the long story short, everything seems to be in order.

Markus
Wes G. (Guest)
on 2006-04-11 20:06
I don't have access to the original file name from a StringIO object
though, correct?

So I will either have to capture the file name another way or just
rename it myself?

Wes

Markus Piff wrote:
> Hi,
>
> this isn't a real problem, which you are experiencing here.
> Due to this CGI stuff, a large "File" gets mapped in a File object,
> whereas
> small files are being represented by StringIO objects. The reason, why
> it is
> done in this way may be performance, but I'm not really sure about this.
>
> To make the long story short, everything seems to be in order.
>
> Markus
Markus Piff (Guest)
on 2006-04-17 00:28
(Received via mailing list)
Hi,

you do have access to the original filename, but the methods are
different.
For StringIO the method should be "original_filename" whereas for File
instances
<http://www.nabble.com/forum/ViewPost.jtp?post=3729...
the method is "path".

So you see, you don't have to rename anything.
Sorry for the late answer, I was quite busy this week.

Markus
Wes G. (Guest)
on 2006-04-17 02:22
Markus,

I was unable to find an original_filename method on the StringIO object.

Are you sure it's there?

Wes
Markus Piff wrote:
> Hi,
>
> you do have access to the original filename, but the methods are
> different.
> For StringIO the method should be "original_filename" whereas for File
> instances
> <http://www.nabble.com/forum/ViewPost.jtp?post=3729...
> the method is "path".
>
> So you see, you don't have to rename anything.
> Sorry for the late answer, I was quite busy this week.
>
> Markus
This topic is locked and can not be replied to.