uploaded file for web.d

This commit is contained in:
Adam D. Ruppe 2011-07-15 13:05:22 -04:00
parent 298dc39ea2
commit 65021528da
2 changed files with 16 additions and 1 deletions

3
README
View File

@ -3,6 +3,9 @@ This is a collection of modules I find generally useful.
Modules are usually independent; you don't need this whole directory
but it doesn't hurt to grab it all either.
Recent changes:
web.d can now accept file uploads via hackish thing - make a param with type "Cgi.UploadedFile"
Currently included are:
Web related

14
web.d
View File

@ -1,6 +1,8 @@
module arsd.web;
/*
FIXME: in params on the wrapped functions generally don't work
Running from the command line:
./myapp function positional args....
@ -571,13 +573,14 @@ immutable(ReflectionInfo*) prepareReflectionImpl(alias PM, alias Parent)(Cgi cgi
}
} else static if (is(typeof(param) == bool)) {
p.type = "checkbox";
} else static if (is(Unqual!(typeof(param)) == Cgi.UploadedFile)) {
p.type = "file";
} else {
if(p.name.toLower.indexOf("password") != -1) // hack to support common naming convention
p.type = "password";
else
p.type = "text";
}
f.parameters ~= p;
}
@ -1034,6 +1037,11 @@ Form createAutomaticForm(Document document, string action, in Parameter[] parame
input.type = type;
input.name = param.name;
input.value = param.value;
if(type == "file") {
form.method = "POST";
form.enctype = "multipart/form-data";
}
}
}
@ -1477,6 +1485,10 @@ WrapperFunction generateWrapper(alias getInstantiation, alias f, alias group, st
args[i] = true; // FIXME: should try looking at the value
else
args[i] = false;
} else static if(is(Unqual!(type) == Cgi.UploadedFile)) {
if(name !in cgi.files)
throw new InsufficientParametersException(funName, "file " ~ name ~ " is not present");
args[i] = cast() cgi.files[name]; // casting away const for the assignment to compile FIXME: shouldn't be needed
} else {
if(using !in sargs) {
throw new InsufficientParametersException(funName, "arg " ~ name ~ " is not present");