www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Vibe.d form file attributes

reply aberba <karabutaworld gmail.com> writes:
In PHP, I am able to access the name attribute of multiple files 
submitted through forms at the server side in $_FILES global.

For example, a file input with name="picture[]" will allow me to 
upload multiples files with the same attribute name. This can be 
access in PHP as;

  $files =  $_FILES["picture"]; // This filter out only files with 
a name attribute of "picture[]"

foreach ($files as $file) {
     $filename = $file["name"];
     ...
}



Now I wanted to implement this in D (vibe.d) and here is what I 
did in the file upload handler.

void upload(HTTPServerRequest req, HTTPServerResponse res)
{
     import std.stdio;

     foreach(picture; req.files) // req.files includes all 
uploaded files
     {
         ...
     }	
}
However, I want to filter out only those files with attribute 
name of "picture[]" from req.files.  I tried req.files.name == 
"picture[]" and other combination but there seem to be no 
property like that (How do I print all properties of req.files by 
the way? :) ).

Any help on this?
Dec 20 2016
parent reply WebFreak001 <d.forum webfreak.org> writes:
On Tuesday, 20 December 2016 at 18:22:51 UTC, aberba wrote:
 [...]
 Now I wanted to implement this in D (vibe.d) and here is what I 
 did in the file upload handler.

 void upload(HTTPServerRequest req, HTTPServerResponse res)
 {
     import std.stdio;

     foreach(picture; req.files) // req.files includes all 
 uploaded files
     {
         ...
     }	
 }
 However, I want to filter out only those files with attribute 
 name of "picture[]" from req.files.  I tried req.files.name == 
 "picture[]" and other combination but there seem to be no 
 property like that
iterate over req.files like this instead: foreach (name, picture; req.files) // name is "picture[]" now { ... }
 (How do I print all properties of req.files by the way? :) ).
pragma(msg, __traits(allMembers, typeof(picture)));
Dec 20 2016
parent aberba <karabutaworld gmail.com> writes:
On Tuesday, 20 December 2016 at 18:42:11 UTC, WebFreak001 wrote:
 On Tuesday, 20 December 2016 at 18:22:51 UTC, aberba wrote:
 [...]
iterate over req.files like this instead: foreach (name, picture; req.files) // name is "picture[]" now { ... }
Nice.
 [...]
pragma(msg, __traits(allMembers, typeof(picture)));
Wow. I have a lot to learn :). PHP had spoon-fed me.
Dec 20 2016