Multiple file uploads - only one file object gets posted


#1

All,

Trying to upload multiple files.

Form:

<% index = 0
for @image in images do %>

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

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


#2

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


#3

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


#4

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=3729395&framed=y
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


#5

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=3729395&framed=y
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