Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MultipartFileRecreatable from dio_smart_retry package #698

Open
DmitryGaimaldinov opened this issue Aug 1, 2024 · 1 comment

Comments

@DmitryGaimaldinov
Copy link

DmitryGaimaldinov commented Aug 1, 2024

Is your feature request related to a problem? Please describe.
I use retrofit with dio_smart_retry package. I want to have ability to retry multipart requests with files. In dio_smart_retry this is done by MultipartFileRecreatable package. I wish retrofit had support to this.

Describe the solution you'd like
I understand that retrofit package will never be dependent of another package like dio_smart_retry. But maybe there's a possibility to have another package which just dio_smart_retry for retrofit.

I've tried to fork retrofit locally and found out that make generator to generate MultipartFileRecreatable instead of MultipartFile is quite simple

// generator.dart. Line 1825.
final isRecreatable = r.peek('recreatable')?.boolValue ?? false; // I've just added `bool recreatable` property to Part annotation but of course this should be done another way

  final uploadFileInfo = refer(
          '${isRecreatable ? MultipartFileRecreatable : MultipartFile}.fromFileSync') // this is where code generated MultipartFile.fromFileSync
      .call([
    refer(p.displayName).property('path')
  ], {
    'filename': fileName,
    if (contentType != null)
      'contentType':
          refer('MediaType', 'package:http_parser/http_parser.dart')
              .property('parse')
              .call([literal(contentType)])
  });

Describe alternatives you've considered
The only alternative right now is to use Dio instead of retrofit in cases when multipart requests with files needs to be retried.

Additional context
There were only one issue in dio_smart_retry about this case rodion-m/dio_smart_retry#39. I guess there's no way to do it without retrofit support

@DmitryGaimaldinov
Copy link
Author

I'm sorry. In first version of my comment above I mentioned that FileSystemException: File closed happens with my attempt to generate MultipartFileRecreatable instead of MultipartFile. But now I guess this exception happens only in my project, so I removed the mention of this exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant