axios
axios copied to clipboard
Reading FormData for the second time will timeout
Describe the bug
If the first request of using form data fails, I need to retry, but the second retry will definitely get stuck and no new request will be sent. It is suspected that the stream has been read and cannot be reused
After trying again, it will get stuck and error timeouts will occur one after another
import axiosRetry from "axios-retry";
import axios from "axios";
import FormData from 'form-data'
const form = new FormData()
form.append('my_field', 'my_value');
const instance = axios.create({
headers: form.getHeaders(),
maxContentLength: Infinity,
});
axiosRetry(instance, {
retries: 3,
retryCondition(error) {
console.log("retrying")
return true
}
});
instance.post('http://example.com/submit-form', form)
.then((response) => {
console.log('Success:', response.data);
})
.catch((error) => {
console.error('Error:', error);
});
To Reproduce
No response
Code snippet
No response
Expected behavior
No response
Axios Version
No response
Adapter Version
No response
Browser
No response
Browser Version
No response
Node.js Version
No response
OS
No response
Additional Library Versions
No response
Additional context/Screenshots
No response
Can confim, im having this problem as well and it really seems that it stems from the consumed stream being, well, already consumed when the request is retried
You can't re-read the stream payload. Use the native FormData & Blob classes or their spec-compliant polyfill like formdata-node (for node older than v18).