How do you handle multiple files in a form submission using Apache2::Upload?

0

Issue

I’m writing a small web application using Perl, HTML::Mason and Apache.

I’ve been using Mason’s usual <%args> method for receiving ‘normal’ form parameters, and Apache2::Upload for receiving files.

However, I want to write a page that allows a user to upload multiple files, and I’d like to take advantage of HTML5’s multiple attribute to input fields. This will look to the server as though there were multiple file inputs in the form with the same name.

The interface for Apache2::Upload doesn’t seem to directly support this, allowing you instead to just get the data for a file with a particular parameter name. The documentation alludes to using APR::Request::Param::Table, but I can’t find any documentation for doing that.

Please note that I’m not interested in answers that involve adding extra file input fields with different names. This is trivial to handle on the server, and my question doesn’t involve front-end scripting at all.

Solution

Use the multiple attribute (in the form as you described) and then, after submission, call the Apache request object’s upload method. That will give you a list of Apache2::Upload instances.

Good luck!

Answered By – Octoberdan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More