-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Bug with the clone() method while retrying FormData requests #1902
Comments
Related to #1889 |
@kuhnroyal @anilslabs I'm taking a look at it but I have a feeling already of what could be going on. |
@gabrielaraujoz Basically, I'm trying to clone the multipart file in the error handler and retrying the unsuccessful request with an updated session token. |
@anilslabs thanks buddy, I could reproduce it. @kuhnroyal I believe the issue lies in us reusing the stream when cloning, specially when using the
MultipartFile(
Stream<List<int>> stream,
this.length, {
this.filename,
MediaType? contentType,
Map<String, List<String>>? headers,
String? filePath,
List<int>? value,
}) : _stream = stream,
headers = caseInsensitiveKeyMap(headers),
contentType = contentType ?? MediaType('application', 'octet-stream'),
_filePath = filePath,
_valueBytes = value;
MultipartFile clone() {
if (_filePath != null) {
return multipartFileFromPathSync(
_filePath!,
filename: filename,
contentType: contentType,
headers: headers,
);
} else if (_valueBytes != null) {
return MultipartFile.fromBytes(
_valueBytes!,
filename: filename,
contentType: contentType,
headers: headers,
);
} else {
throw ArgumentError(
'Operation is not possible, file path or value is not available');
}
} WDYT? I'll open a PR with this code for you to check. |
What if we deprecate the |
@kuhnroyal I'm not sure it resolve this issue when it comes to the |
Well if it is a Stream provider function, then you get a new Stream every time you call it. |
I'll look into it @kuhnroyal - in the meanwhile, I've tested the proposed solution from the PR in my production app in stg and it worked as intended! |
@kuhnroyal you're amazing, the solution with the stream provider function worked! I already updated the PR and also:
|
@anilslabs hey, this PR should fix your issue in case you're in an emergency: #1903 |
@gabrielaraujoz Thanks. I have tested with the PR and the issue is fixed. Awaiting a pub.dev release. |
@AlexV525 hey Alex, sorry to bother you, but do we have any forecast on when we'll be able to have the fix released? |
Generally I'll do a week cycle for publishing. You can use overrides to use the patch if it's urgent. |
Package
dio
Version
5.3.0
Output of
flutter doctor -v
Dart Version
3.0.5
Steps to Reproduce
Expected Result
The file should be uploaded to the server with an updated user session token.
Actual Result
Getting the following exception:
The text was updated successfully, but these errors were encountered: