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

wjoe invalid at example.com
Thu Sep 17 17:08:48 UTC 2020


On Thursday, 17 September 2020 at 16:32:55 UTC, WebFreak001 wrote:
> 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.

Every post or example I found copies the file, like your code 
does, too. Why is that ? The content of the file upload is 
embedded in the form data. There's no need for temporary files or 
copying at all.

On top of that, if I upload a file to a server which is on a 
different PC on a different file system, how am I supposed to 
read the file from disk on a remote file system ?

This makes no sense.

What I want is something like this:

> ~$ cat /var/log/temperatures.log
>
> temp_1=22;temp_2=28
> temp_1=21;temp_2=25


> ~$ curl -F "temperature_log=@/var/log/temperatures.log" 
> 192.168.1.1:20222/temperature_upload

> ~$ nc -l 127.0.0.1 20222
>
> POST /temperature_upload HTTP/1.1
> Host: 192.168.1.1:20222
> User-Agent: curl/7.72.0
> Accept: */*
> Content-Length: 245
> Content-Type: multipart/form-data; 
> boundary=------------------------c73c71472ff9e7d5
>
> --------------------------c73c71472ff9e7d5
> Content-Disposition: form-data; name="temperature_log"; 
> filename="/var/log/temperatures.log"
> Content-Type: application/octet-stream
>
> temp_1=22;temp_2=28
> temp_1=21;temp_2=25
>
> --------------------------c73c71472ff9e7d5--


void upload(HttpRequest.. req, blah)
{
    auto file = "temperature_log" in req.files;
    if (file) {
       string temp_data_raw = file.data;
       assert ("temp_1=22;temp_2=28\ntemp_1=21;temp_2=25" == 
temp_data_raw);
    }
}



More information about the Digitalmars-d-learn mailing list