How do I access posted form data and files when using Shelf?

28 views Asked by At

New to Dart and writing an HTTP server using Shelf and I can't seem to find a straightforward way to grab my posted form data (and uploads) from the Request object -- not sure why a simple thing like this has been deliberately made hard? There's a getter called params on the Request object but it seems to return path params (now why would anyone break a well known pattern like this?)? Sorry, end of rant, can someone with more understanding please help?

1

There are 1 answers

0
Nigel Savage On

Here is a possible solution using only native dart,
Flow is

  1. get form data as a string

  2. url decode the form data string using the dart Uri class

  3. again with the Uri class parse the form data to a map.

     var bodyString = await request.readAsString();
     bodyString = Uri.decodeFull(bodyString);
     final dmap = Uri.splitQueryString(bodyString);
    

enter image description here