1

How I get original bytes from request? Calling request.body.asBytes() I get this message:

asBytes() expected list of bytes, instead got List<_InternalLinkedHashMap<String, dynamic>>

I saw that HTTPRequestBody has the property retainOriginalBytes to use in this case, but where I set it?

Thanks!

Ricardo Bocchi
  • 1,551
  • 2
  • 12
  • 12
  • Can you show a lager example of what you do, so it's possible to recreate it. I'd say that, at the very least, the error message should be better. – lrn Nov 20 '17 at 08:17
  • this message is thrown when `request.body.as Bytes()` is calling in anywhere of controller. Using `retainOriginalBytes` correctly resolved the problem – Ricardo Bocchi Nov 23 '17 at 12:44

2 Answers2

0

Whatever endpoint you're hitting with your request is returning a Map in its body, not a list of Bytes.

I'm not sure if you can control the contents of what that endpoint is returning but if you can that would be the place to change it.

Check out the BytesBuilder class. Also, read the Aqueduct docs for Request and Response Objects. Hopefully this gets you on the right path!

leerob
  • 2,876
  • 1
  • 18
  • 38
0

You're on the right track; this will work correctly once you've set retainOriginalBytes to true. This must be done before the body is decoded.

In an HTTPController, the request body is decoded before your method that handles the request is called. Just before the decoding, HTTPController calls its willDecodeRequestBody() method. This method does nothing by default, but you can override it to set retainOriginalBytes:

@override
void willDecodeRequestBody(HTTPRequestBody body) {
  body.retainOriginalBytes = true;
}

Here is an example of an application that does this.

Joe Conway
  • 1,566
  • 9
  • 8