On 9/17/20 6:13 PM, aberba wrote:
On Thursday, 17 September 2020 at 21:57:37 UTC, Steven Schveighoffer wrote:
On 9/17/20 1:08 PM, wjoe wrote:
[...]
the `files` property actually does the processing only when you call it.
If you access the `bodyReader` property directly, you can process that
data yourself. You can even register a web interface function with an
`InputStream` parameter type, and it will be bound to the body data.
I'm not sure I understand how to do this and parser the files in memory.
So an HTTP request with form data will come in with the headers parsed,
but the data is still on the network stream.
The first time you access `files`, it processes the stream data, and
splits it into form data and file data, saves the files, and then gives
you back the file dictionary so you can use them.
If instead, you access `bodyReader`, YOU get to process the form data
and file data.
I've done this with my REST interface, though that's not form data.
That's not a great API, though. I would love to see vibe.d allow a
direct call to vibe.inet.webform.parseFormData with a specific handler
for files and form data.
Can we file an issue for this? Because I'm very interested in having
this resolved
You can always file an issue! https://github.com/vibe-d/vibe.d/issues
There may already be one in there.
There's potential to results in out of memory condition. Its a know
issues. A complete parser (like multer in nodejs) allowance you to limit
file size as well for error handling.
Meh, this is D :) we should be able to just process the data and do
whatever we want with it. What I would like to see is vibe provide the
parsing of form data, and just give me the data as it comes (kind of
like a SAX parser). Maybe just a property in the HTTPServerRequest that
I can set that says "use this callback when you get Form File data".
I've done this with my REST interface, though that's not form data.
Can you share your code for this?
Heh, this is not form data, it's just file data, raw on the stream. So I
have a function like:
```
class FileRestImpl
{
@path(":cat/:id/:uuid/upload")
@getAuth
void postUpload(HTTPServerResponse res, string _cat, int _id,
string _uuid, InputStream stream, Nullable!string md5sum, NRMAuthInfo
_authInfo)
{
...
}
}
```
You can see, I take an InputStream as a parameter -- the data comes in
there. I just read it and save it to a file (in the correct location)
anyway, verifying the md5sum is valid.
-Steve