#1391 ✓worksforme
Cyril

Multiple file uploads only show the first file

Reported by Cyril | January 24th, 2012 @ 02:06 PM | in 1.2.5 (closed)

Please include as much relevant information as possible including the exact framework version you're using and a code snippet that reproduces the problem. WARNING: Do not fill bugs related describing security vulnerabilities. Email directly guillaume dot bort at gmail dot com for that.

Framework version: 1.2.4
Platform you're using: Linux Fedora 16 64b

HTML Example form :

<form method="post" action="/upload" enctype="multipart/form-data">
    <input type="file" name="image" />
    <input type="file" name="image" />
    <input type="file" name="image" />
    <input type="file" name="image" />

    <input type="submit" name="submit" value="Send images" />
</form>

In your method, you can try with this :

File[] images = params.get("image", File[].class);
Upload[] images = params.get("image", Upload[].class);
List<File> images = params.get("image", List<File>.class);
List<Upload> images = params.get("image", List<Upload>.class);
List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");

or put directly in the method's signature, one of them :

  • File[]
  • Upload[]
  • List
  • List

The result will be the same : Only the first file is used, but as many times as there is a file input (4 times in my case)

(A StackOverflow question has been opened, and a Google Groups also, but without any answers, so that's why I think its a bug.)

Comments and changes to this ticket

  • Jostein Austvik Jacobsen

    Jostein Austvik Jacobsen January 31st, 2012 @ 10:55 AM

    I'm having the same issue. And I can't use the methods signature, since I don't know the names of the parameters in advance. The input fields are generated based on templates, and will result in stuff like this:



    Then I want to go through each parameter starting with "input-" and assume that it is either a File or a File[] array. Doing "File[] files = params.get("input-fileA", File[].class);" just gives the first file in that array (as many times as there are files in the array) like in the reported bug.

  • Nicolas Leroux

    Nicolas Leroux February 21st, 2012 @ 07:01 PM

    • Assigned user set to “Nicolas Leroux”
    • Milestone set to 1.2.5
    • Milestone order changed from “1006” to “0”
  • Nicolas Leroux

    Nicolas Leroux February 21st, 2012 @ 08:34 PM

    • State changed from “new” to “confirmed”
  • Nicolas Leroux

    Nicolas Leroux February 21st, 2012 @ 08:38 PM

    However, it should work with file

    <input type="file" multiple >
    
  • Nicolas Leroux

    Nicolas Leroux February 21st, 2012 @ 08:48 PM

    • State changed from “confirmed” to “worksforme”

    It works for me. I have the following code:

    Application.java

    public class Application extends Controller {
    
        public static void index() {
            render();
        }
     
        public static void upload(File[] files) {
            for (File file : files) {
                Logger.info("file " + file.getName());
            }
        } 
    
    }
    

    index.html

    <form method="post" action="@{Application.upload}" enctype="multipart/form-data">
        <input type="file" name="files" />
        <input type="file" name="files" />
        <input type="file" name="files" />
        <input type="file" name="files" />
    
        <input type="submit" name="submit" value="Send images" />
    </form>
    
  • Nicolas Leroux

    Nicolas Leroux February 21st, 2012 @ 09:11 PM

    If you are using a

    List<File>
    

    please not that you should have the following html:

    <form method="post" action="@{Application.upload}" enctype="multipart/form-data">
        <input type="file" name="files[0]" />
        <input type="file" name="files[1]" />
        <input type="file" name="files[2]" />
        <input type="file" name="files[3]" />
    
        <input type="submit" name="submit" value="Send images" />
    </form>
    

    This is because list are ordered.

  • Cyril

    Cyril February 27th, 2012 @ 01:34 PM

    That's really odd because I updated my code to copy yours :

    public static void upload(File[] files) {
        for (File file : files) {
            Logger.info("file " + file.getName());
        }
    }
    

    And it doesn't work. I have x times the first file, and that's it!

    Which version are you using?
    The 1.2.4 or a built version of the HEAD? (maybe it has been fixed inadvertently! :p)

  • Jostein Austvik Jacobsen
  • Cyril

    Cyril March 2nd, 2012 @ 09:03 AM

    If only a hackish version is working, this means a bug is trully present IMHO.

    I'll try to get the HEAD version of Play! and try if it has been fixed by "inadvertance" (while fixing an other bug).

  • Sander

    Sander March 10th, 2012 @ 06:47 PM

    I'm having the same problem with 1.2.4 and the multiple file input. The files are present in the upload directory (tmp/uploads/...) but the array that is passed on contains only the first file n times (n=number of files). Win7 64bit Java 1.7.3

  • Sander

    Sander March 11th, 2012 @ 10:07 PM

    Sorry forgot the code:

    public static void postNewAlbumPhoto(File[] photoFiles) {
        for (File photofile : photoFiles) {
            try {
                //dosomestuff
            } catch (IOException ex) {
            }
        }
    }
    
    <form method="POST" action="@{MyAdmin.postNewAlbumPhoto()}" enctype="multipart/form-data" >
            <input type="file"  name="photoFiles" id="photoFiles" multiple="multiple"/> <br />
            <input type="submit" value="submit" />
        </form>
    
  • Imogen Phelan

    Imogen Phelan November 10th, 2018 @ 05:54 AM

    Project of the light house has been ensured for the good and all normative basis for the individuals. The role of the science and thesis best is introduced for the introduction for the lights of the homes.

  • Hard Work

    Hard Work January 23rd, 2019 @ 06:22 AM

    Here you will be able to find out one of the foremost portal windows 10 desktop icon which will also help you to clarify all your hurdles and will also provide you all exact information for the same path as here it is an hub of information which will display you in the form of images.

  • Ted Johnson

    Ted Johnson April 12th, 2019 @ 09:18 AM

    This post is not just informative but impressive also. The post is so convincing that it created an urge to choose Dissertation Help Services. You can email us at info@ukdissertationhelp.co.uk or Phone Number: 020 8144 9988.
    Dissertation Writing Services

  • muneer ahmed

    muneer ahmed April 18th, 2019 @ 08:10 AM

    The online marketing company in Warmenhuizen, All our offices in The Netherlands: Amsterdam city, Tilburg, Leiden, Rotterdam city and main office Schagen. Backlink strategy with high metrics values as part of of page seo to boost ranking in Google serp. Gravatar website optimization

  • zeniya

    zeniya May 29th, 2019 @ 07:14 AM

    I have faced the same situation when I try to upload multiple files clipping path company. We started to upload all the files, finally, we could only see the first files in the folder. Why is it so? Try to share the reason behind and also the solution for it.

  • Debra Hammons

    Debra Hammons July 11th, 2019 @ 10:38 AM

    We also have the same problem with code at dissertation service, thanks for referal to stackoverflow

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2>Play framework</h2>

Play makes it easier to build Web applications with Java. It is a clean alternative to bloated Enterprise Java stacks. It focuses on developer productivity and targets RESTful architectures. Learn more on the <a href="http://www.playframework.org">http://www.playframework.org</a> website.<br><br>

<h2>Source code is hosted on github</h2>Check out our repository at <a href="http://github.com/playframework/play">http://github.com/playframework/play</a><br><br>

<h2>Contributing, creating a patch</h2> Please read the <a href="http://play.lighthouseapp.com/projects/57987/contributor-guide">contributor guide</a><br><br>

<h2>Reporting Security Vulnerabilities</h2> Since all bug reports are public, please report any security vulnerability directly to <em>guillaume dot bort at gmail dot com</em>.<br><br>

<h2>Creating a bug report</h2> Bug reports are incredibly helpful, so take time to report bugs and request features in our ticket tracker. We’re always grateful for patches to Play’s code. Indeed, bug reports with attached patches will get fixed far quickly than those without any.<br><br>

Please include as much relevant information as possible including the exact framework version you're using and a code snippet that reproduces the problem.<br><br>

Don't have too much expectations. Unless the bug is really a serious "everything is broken" thing, you're creating a ticket to start a discussion. Having a patch (or a branch on Github we can pull from) is better, but then again we'll only pull high quality branches that make sense to be in the core of Play.

Pages