Cro: libraries and tools for building reactive services in Perl 6 | cro.services/ | Logs: irclog.perlgeek.de/cro/
Set by moderator on 23 January 2018.
02:58 ilbot3 joined
moderator Cro: libraries and tools for building reactive services in Perl 6 | cro.services/ | Logs: irclog.perlgeek.de/cro/
03:50 Geth joined 05:58 b2gills joined 08:48 sena_kun joined 17:11 lizmat joined 17:12 kolikov joined
kolikov Hi ! 17:13
Just question about fetching a file from a multipart form ... 17:14
When I try to fetch and save a png using : request-body-blob -> $blob { spurt('/home/somepath/out.png', $blob, :bin, :w); } 17:16
jnthn ...then you get a bunch of useless bytes? :) 17:17
kolikov $blob is a Buf object, not a blob.
jnthn A Buf is a Blob
But if it's a multi-part form then the blob there will be the bytes of the entire multi-part document, not one file from it 17:18
kolikov Ok ! So how do i get the data without going down the whole "request-body"
jnthn The body will be parsed. request-body -> $body { } will give you a Cro::HTTP::Body::MultiPartFormData in $body 17:20
That can be used like a hash with the field name 17:21
timotimo oh, what happens if the same field name is used twice in a multipart message? is that specced?
jnthn Then the hash indexing gives you a Cro::MultiValue :) 17:22
You can also go over the .parts in order
Anyway, $body<the-upload-control-name>.body-blob should do it 17:23
$body<the-upload-control-name>.filename would give you the filename that was uploaded, if that is of interest
You can also
request-body -> (:$the-control-name, *%) { $the-control-name.body-blob }
kolikov The Cro::MultiValue is also set when i send an input type="file" with the multiple tag 17:24
jnthn Yup, and it's just a List really
timotimo well, i hope lots of code is prepared to handle a multivalue where they expect a singlevalue :)
kolikov Ok tha clarifies a lot of thing ... thanks a lot :-) 17:25
17:49 lizmat joined 18:18 lizmat joined
kolikov Bye o/ 18:33
19:13 lizmat joined 19:32 lizmat joined 19:59 lizmat joined 20:12 lizmat joined 23:28 lizmat joined