Skip to content

How to handle "chunked" content-encoding in Flutter using Dio? #2177

Closed Answered by MyFakeHub
MyFakeHub asked this question in Q&A
Discussion options

You must be logged in to vote

The solution was to use a Brotli transformer to unzip (or decompress) the response data.

The Content-Encoding of the response header was set to br which (I didn't know) means the data was compressed using the Brotli algorithm. I then used this package that automatically transforms the data into JSON. No need to receive the data as bytes or as a stream.

The code looks something like this

dio.transformer = DioBrotliTransformer();
Response response = await dio.get(endpoint); // no need for options: Options(responseType: ResponseType.bytes)

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@MyFakeHub
Comment options

@kuhnroyal
Comment options

@MyFakeHub
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by MyFakeHub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants