RejectedSoftware Forums

Sign up

Upload more than 1 image.

Hi, I'm trying to upload more than 1 image at a time.

My client side form is:

form(method="POST", action="/photo_upload", enctype="multipart/form-data")
    input(type="file", name="imagesToUpload", id="imagesToUpload", multiple)
    button(type="submit", id="doUploadButton") Upload

And server side (I havent implemented the file copyies yet, I'm only reading the info from the headers for now)

private void postPhotoUpload(HTTPServerRequest req, HTTPServerResponse res){
    import std.stdio;
    debug{
        writefln("req headers:");
        foreach(key, val; req.headers)
             writefln("\t%s : %s",key, val);

        writefln("req files:");
        foreach(key, val; req.files)
            writefln("\t%s : %s", key, val);
    }
    res.writeBody("Test upload", "text/plain");
}

Again, I havent implemented the actual file copies yet, however, I can see from the req.files array that only 1 file is ever being populated there.

This is the output when I select two files to upload via the client.

imagesToUpload : FilePart(DictionaryList!(string, false)([Field(575136612, "Content-Disposition", "form-data; name=\"imagesToUpload\"; filename=\"image.png\""), Field(982413131, "Content-Type", "image/png"), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", "")], 2, []), image.png, /tmp/vtmp.VBh4mv)

Any idea whats going on here?
Thanks!

Re: Upload more than 1 image.

On Wed, 26 Feb 2014 23:21:18 GMT, Colin Grogan wrote:

Hi, I'm trying to upload more than 1 image at a time.

My client side form is:

form(method="POST", action="/photo_upload", enctype="multipart/form-data")
    input(type="file", name="imagesToUpload", id="imagesToUpload", multiple)
    button(type="submit", id="doUploadButton") Upload

And server side (I havent implemented the file copyies yet, I'm only reading the info from the headers for now)

private void postPhotoUpload(HTTPServerRequest req, HTTPServerResponse res){
    import std.stdio;
    debug{
        writefln("req headers:");
        foreach(key, val; req.headers)
             writefln("\t%s : %s",key, val);

        writefln("req files:");
        foreach(key, val; req.files)
            writefln("\t%s : %s", key, val);
    }
    res.writeBody("Test upload", "text/plain");
}

Again, I havent implemented the actual file copies yet, however, I can see from the req.files array that only 1 file is ever being populated there.

This is the output when I select two files to upload via the client.

imagesToUpload : FilePart(DictionaryList!(string, false)([Field(575136612, "Content-Disposition", "form-data; name=\"imagesToUpload\"; filename=\"image.png\""), Field(982413131, "Content-Type", "image/png"), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", "")], 2, []), image.png, /tmp/vtmp.VBh4mv)

Any idea whats going on here?
Thanks!

Looking at the file that actually gets through, its always the last one I select. My guess is that because req.files is an array[string], and the key is the same in each case, the array[string] is just over-ridden every time. Would this make sense?

Re: Upload more than 1 image.

On Wed, 26 Feb 2014 23:32:20 GMT, Colin Grogan wrote:

Looking at the file that actually gets through, its always the last one I select. My guess is that because req.files is an array[string], and the key is the same in each case, the array[string] is just over-ridden every time. Would this make sense?

Yes, I guess that's exactly the case. I'll change the type of req.files to use a DictionaryList!(FilePart, true) instead of an associative array (like req.form and req.query already do).

Re: Upload more than 1 image.

On Thu, 27 Feb 2014 08:15:17 GMT, Sönke Ludwig wrote:

On Wed, 26 Feb 2014 23:32:20 GMT, Colin Grogan wrote:

Looking at the file that actually gets through, its always the last one I select. My guess is that because req.files is an array[string], and the key is the same in each case, the array[string] is just over-ridden every time. Would this make sense?

Yes, I guess that's exactly the case. I'll change the type of req.files to use a DictionaryList!(FilePart, true) instead of an associative array (like req.form and req.query already do).

Great, thanks!

Re: Upload more than 1 image.

On Thu, 27 Feb 2014 09:15:56 GMT, Colin Grogan wrote:

On Thu, 27 Feb 2014 08:15:17 GMT, Sönke Ludwig wrote:

On Wed, 26 Feb 2014 23:32:20 GMT, Colin Grogan wrote:

Looking at the file that actually gets through, its always the last one I select. My guess is that because req.files is an array[string], and the key is the same in each case, the array[string] is just over-ridden every time. Would this make sense?

Yes, I guess that's exactly the case. I'll change the type of req.files to use a DictionaryList!(FilePart, true) instead of an associative array (like req.form and req.query already do).

Great, thanks!

Implemented by 7a090b2 (it's still on the 0.7.20 branch* until 0.7.19 is released)

* if anyone asks themselves why there is no 0.7.19 branch instead and development happens on master: It's just due to a limitation of the current CI server, which will be fixed in a while.

Re: Upload more than 1 image.

On Thu, 27 Feb 2014 09:32:14 GMT, Sönke Ludwig wrote:

On Thu, 27 Feb 2014 09:15:56 GMT, Colin Grogan wrote:

On Thu, 27 Feb 2014 08:15:17 GMT, Sönke Ludwig wrote:

On Wed, 26 Feb 2014 23:32:20 GMT, Colin Grogan wrote:

Looking at the file that actually gets through, its always the last one I select. My guess is that because req.files is an array[string], and the key is the same in each case, the array[string] is just over-ridden every time. Would this make sense?

Yes, I guess that's exactly the case. I'll change the type of req.files to use a DictionaryList!(FilePart, true) instead of an associative array (like req.form and req.query already do).

Great, thanks!

Implemented by 7a090b2 (it's still on the 0.7.20 branch* until 0.7.19 is released)

* if anyone asks themselves why there is no 0.7.19 branch instead and development happens on master: It's just due to a limitation of the current CI server, which will be fixed in a while.

Have quickly tested it, it works! Will let you know if theres any other issues with this change.
Thanks again.