Open H3tansh opened 1 month ago
:warning: | Missing Reproducible Example |
---|---|
:information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
Hello,
I've come across your issue and would like to suggest a couple of potential solutions that might resolve the problem you're experiencing with FormData
on Android.
Firstly, ensure that the URI for the file you're appending to FormData
has the correct scheme. On Android, the file URI should start with file://
. Additionally, verify that the MIME type is accurate. For audio files, instead of 'audio/mp3', you should use 'audio/mpeg'.
Here's an updated snippet of your code with these changes:
const formData = new FormData();
formData.append('audio_file', {
name: fileName,
type: 'audio/mpeg', // Correct MIME type
uri: `file://${filePath}` // Correct URI scheme
});
try {
const response = await fetch('http endpoint', {
body: formData,
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
Authorization: 'Bearer token'
}
});
console.log('test result ', response);
console.log('test result status ', response.status);
} catch (e) {
console.error('test error ', e);
}
accurate
Tried everything including your suggestion, still no luck 😓
Description
Cannot Make API call to http endpoint when using formData[Tried with both fetch and axios]
I've tried addring clearTextTrafic true in android Mainfest.xml file
Working fine in iOS, and working well with normal APIs ( without formData), only API with formData having this issue.
Steps to reproduce
const formData = new FormData() formData.append('audio_file', { name: fileName, type: 'audio/mp3', uri: filePath })
This returns network error
React Native Version
0.74.1
Affected Platforms
Runtime - Android
Output of
npx react-native info
Stacktrace or Logs
Reproducer
private repo cannot provide link
Screenshots and Videos
No response