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

fix: Fix multipart/form-data request resending #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

papertigify
Copy link

Problem

  1. We make a multipart/form-data request.
  2. The response returns an authorization token error.
  3. Fresh 🍋 kicks in, successfully refreshes the token, and retries the request.
  4. ❌ We get a Dio error:
    “The FormData has already been finalized. This typically means you are using the same FormData in repeated requests.”

Solution

Dio provides the FormData.clone() method, specifically designed to solve this issue. Dio documentation for the method states:
“Convenience method to clone finalized FormData when retrying requests.”

We just need to check the type of RequestOptions.data and call clone() if RequestOptions.data is FormData.

@papertigify
Copy link
Author

@felangel the issue was previously discussed here #52

return _httpClient.request<dynamic>(
response.requestOptions.path,
cancelToken: response.requestOptions.cancelToken,
data: response.requestOptions.data,
data: data is FormData ? data.clone() : data,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test for this fix to ensure a regression doesn’t occur? Thanks!

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

Successfully merging this pull request may close these issues.

2 participants