chopper icon indicating copy to clipboard operation
chopper copied to clipboard

[Feature request] Multipart request progress support

Open pierremrtn opened this issue 2 years ago • 3 comments

It would be great to have a way to get the upload progress of multipart requests. An example of how to achieve this with http package can be found here. Maybe by adding a new annotation? Something like:

  @Post(path: '/file')
  @Multipart()
  Future<Response<void>> uploadFile(
    @Query('filename') String fileName,
    @PartFile() String filePath,
    /// A callback that take the progress of the upload as a double between 0 and 1
    @ProgressCallback() void Function(double) progressCallback,
);

pierremrtn avatar Sep 22 '22 09:09 pierremrtn

When looking at the example it looks like its actually using the HttpClient from dart.io instead of http dart package which chopper is using. Reading into some more documentation the http package lists using StreamedRequest as a possibility.

I think it take a bit more investigation on figuring out how too get the progress :)

Guldem avatar Jan 10 '23 09:01 Guldem

Looks to me that the easy way to do this would be to extend the http packages MultipartRequest and override the finalize method to include the progress callback.
Is there any appetite to do that within this library or is the plan to just wait for something like the following which doesn't seem to be getting the attention that it deserves. https://github.com/dart-lang/http/pull/579

bmadaras avatar Mar 17 '23 15:03 bmadaras

Haven't had the time to further investigate this. There is also this https://github.com/dart-lang/http/pull/728 PR which has a bit more attention and also adds a upload progress to the http client. Would be nice if it was included and easier intergrading in chopper. But that no guarantee.

What I did look into was that it might be possible to finalize the MultipartRequest which results in a ByteStream which maybe could be used in a StreamedRequest. This could be done by creating a extended MultipartRequest or just a method converting the MultipartRequest to StreamedRequest. But feels a bit hacky converting the Request types.

Guldem avatar Mar 29 '23 07:03 Guldem