Skip to content

fix(fresh_dio): clone FormData on retry#113

Merged
felangel merged 3 commits intofelangel:masterfrom
papertigify:fix/retry-multipart-request
Mar 2, 2025
Merged

fix(fresh_dio): clone FormData on retry#113
felangel merged 3 commits intofelangel:masterfrom
papertigify:fix/retry-multipart-request

Conversation

@papertigify
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

@felangel the issue was previously discussed here #52

Comment thread packages/fresh_dio/lib/src/fresh.dart
@papertigify papertigify requested a review from felangel March 1, 2025 10:25
Copy link
Copy Markdown
Owner

@felangel felangel left a comment

Choose a reason for hiding this comment

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

LGTM thanks so much for the contribution! 💙

@felangel felangel changed the title fix: Fix multipart/form-data request resending fix(fresh_dio): clone FormData on retry Mar 2, 2025
@felangel felangel added the bug Something isn't working label Mar 2, 2025
@felangel felangel merged commit 64e5934 into felangel:master Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants