retrofit.dart
retrofit.dart copied to clipboard
Add support for MultipartFileRecreatable from dio_smart_retry package
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 https://github.com/rodion-m/dio_smart_retry/issues/39. I guess there's no way to do it without retrofit support