Skip to content

Download block UI thread with small file #193

Open
@Crash--

Description

@Crash--

I'm using RNFS for downloading file inside an app. Sometimes I can use the app during a download but sometimes not.

I've tested with a small file (~10Mo) and the bug occurs, but with a large file (~1Go) it doesn't.

When I check the log with XCode, I can see, with the small file, that the percentage displayed within the app is not the same that it displayed within Xcode. But with the big file I don't have this problem.

I just tested on Android too, and I get the same weird behavior.

Here is the code I'm using. I tried without progressDivider but same result.

download = (idCourse) => {
    begin = (res) => {
      if (res.statusCode == '404') {
        this.props.cancelDownload(this.props.course.id_course)
        return false
      } else {
        this.jobId = res.jobId
        this.props.setPercentage(this.props.course.id_course, 0, this.jobId)
      }
    }

    progress = (data) => {
      const percentage = ((100 * data.bytesWritten) / data.contentLength) | 0;
      this.props.setPercentage(this.props.course.id_course, percentage, this.jobId)
    }
    const localPath = this.props.course.id_course + '.zip';
    const remoteURL = getCourseZipUrl(this.props.course.id_course)
      const downloadDirectory = Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath + '/downloads/' : RNFS.ExternalDirectoryPath + '/downloads/';

      const realLocalPath = downloadDirectory + '/' + localPath;
      const progressDivider = 1;
      const ret = RNFS.downloadFile({fromUrl: remoteURL, toFile: realLocalPath, begin, progress, false, progressDivider})
      ret.promise.then(res => {
        if (res.statusCode == '404') {
          this.props.cancelDownload(this.props.course.id_course)
        } else{
          this.props.setFinished(this.props.course.id_course)
        }
      }).catch(err => {
        console.log('errorDL', err)
      })
  }

 stopDownload = (idJob) => {
    if (idJob !== -1) {
      RNFS.stopDownload(idJob);
      this.props.cancelDownload(this.props.course.id_course)
    }
  }

Without the bug

download_without_bug

With the bug

bug_dl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions