react-native-blob-util: Not getting continuous upload progress in iOS
Hi,
In iOS the upload progress is not continuous whereas in android is getting continuous progress.
Sample code:
import RNFetchBlob from 'react-native-blob-util';
const apiPostdata = [
{
data: RNFetchBlob.wrap(imageUri),
filename: imageUri.replace(/^.*[\\\/]/, ''),
name: imageField,
type: 'image/jpg'
},
...apiBodyUpdated
];
const apiHeader: Record<string, any> = header || {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'multipart/form-data'
};
return RNFetchBlob
.config({ IOSBackgroundTask: true })
.fetch('POST', apiUrl, apiHeader, apiPostdata)
.progress((received, total) => {
if (progress) {
progress(received / total);
}
})
.uploadProgress(
{ interval: 1 }, (written, total) => {
console.log(written / total, 'written / total'); // => always returns 1 in iOS but in android its progress from 0 to 1
if (progress) {
progress(written / total);
}
}
)
.then((res) => {
if (res.respInfo.status === 201) {
return res.json();
}
return res;
})
.catch((error) => Promise.reject(error));
Here in .progress(), written/ total always return 1 in iOS while uploading but in android value ranges from 0 to 1 thus getting a continuous progress.
Versions using:
react-native-blob-util: 0.13.13 react-native: 0.64.0 react: 17.0.1 Android Studio: 4.1 AI-201.8743.12.41.7199119 Xcode: 12.5.1/12E507
In iOS
In Android
Is there anything that is missing or is it the default behaviour in iOS ?
Thanks.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (1 by maintainers)
I have the same problem in iOS. have anyone fixed it?
First of all, thanks for your quick reply, @filipef101!
The
didReceiveData()function in ReactNativeBlobUtilRequest.mm is only called a single time for a downloaded file, with thereceivedBytesvalue set to the total file size.I thought this might have to do with the configuration of our server where the file is loaded from, but even when trying to download an image from a placeholder service (in my case, https://placehold.co/1920x1080.png), the progress event is fired only once with 100%.EDIT: When using a placeholder service (in my case, https://placehold.co/1920x1080.png), the progress event is fired multiple times and works correctly. So this is not a bug in the awesome
react-native-blob-utilmodule, but a misconfiguration of our server that hosts the images that are downloaded. Sorry for stealing your time!That’s a good question - but in general all events arepassed as string or dict to JS . For the future only strings. But likely the typecast is simply missing.