react-native-fs
react-native-fs copied to clipboard
[Android] uploadFiles progress is inaccurate when binaryStreamOnly is set
On Android, when binaryStreamOnly
is set to true
, progress updates record an inaccurate number for totalBytesSent
. Specifically, according to progress updates, totalBytesSent
is equal totalBytesExpectedToSend
long before the files are actually uploaded and the upload promise resolves. Depending on internet speed, several minutes can pass between the final progress update and the upload actually completing.
Representative code:
const uploader = RNFS.uploadFiles({
toUrl: uploadUrl,
method: 'PUT',
binaryStreamOnly: true,
files: [
{
name: 'currentUpload.zip',
filename: 'currentUpload.zip',
filepath: zipPath,
filetype: 'zip',
},
],
progress: (progress) => {
// progress.totalBytesSent equals progress.totalBytesExpectedToSend long before uploader.promise resolves (sometime minutes)
setProgress(
(progress.totalBytesSent / progress.totalBytesExpectedToSend),
);
},
});
// Wait for the upload to finish
const uploadResponse = await uploader.promise;
same here+