vibe.d: How to get the conent of a file upload ?

WebFreak001 d.forum at webfreak.org
Thu Sep 17 16:32:55 UTC 2020


On Thursday, 17 September 2020 at 16:00:33 UTC, wjoe wrote:
> I found this [1] but unfortunately the post this refers to is a 
> dead link and the content, unfortunately, didn't tell me 
> anything that I didn't already find in the docs.
>
> What I can get from the form is the form fields with content, 
> the field name for the file upload and the file name. But the 
> file name is useless to me because I need the file content.
>
> Where is it stored ?
>
> [1] https://aberba.com/2017/multiple-file-upload-in-vibe-d/

hi, you can access HTTPServerRequest.files which contains the 
uploaded file.

Example in real code: 
https://github.com/WebFreak001/ImageUploader/blob/master/source/app.d#L141-L159

Documentation: https://vibed.org/api/vibe.inet.webform/FilePart

Note: the file is only downloaded from the client / stored on 
disk once you access the files or the form property, though this 
isn't documented.

I don't believe the temp file behavior is customizable as it is 
hardcoded here to write to a temporary file (which is called on 
form parsing): 
https://github.com/vibe-d/vibe.d/blob/ebebfa827f568cc9bced4bec2b66edc043a8adf7/inet/vibe/inet/webform.d#L311

However if you really wanted to (but I'd advise against it) you 
could parse the form data from the HTTPServerRequest.bodyReader 
yourself


More information about the Digitalmars-d-learn mailing list