react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

[Android] uploadFiles progress is inaccurate when binaryStreamOnly is set

Open arcticfly opened this issue 2 years ago • 1 comments

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;

arcticfly avatar Aug 30 '22 07:08 arcticfly

same here+

barbarossusuz avatar May 30 '24 12:05 barbarossusuz