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

no progress callback when I download a small file

Open chuhangyu opened this issue 6 years ago • 4 comments

I tryed to download a small file, around 0.02M, there was no progress returned back, but if the file is big enough, the progress function worked well.

chuhangyu avatar May 10 '18 07:05 chuhangyu

Please provide your code and configuration and tell us on which OS you was testing.

In general: download-process will not download byte by byte and trigger the progress-callback, it will download in larger chunks. If your file is smaller than a chunk, only one progress would be there. The end.

Anyway, have you played with progressDivider?

From README:

If options.progressDivider is provided, it will return progress events that divided by progressDivider.

For example, if progressDivider = 10, you will receive only ten callbacks for this values of progress: 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 Use it for performance issues. If progressDivider = 0, you will receive all progressCallback calls, default value is 0.

itinance avatar May 10 '18 07:05 itinance

	download = () => {
		const testWord = "http://cdn.applan.org/test.docx";
		const options = {
			fromUrl: testWord,
			toFile: RNFS.DocumentDirectoryPath + '/test.docx',
			background: true,
			begin: (res) => {
				console.log('begin', res);
				console.log('contentLength:', res.contentLength / 1024 / 1024, 'M');
			},
			progress: (res) => {
				let pro = res.bytesWritten / res.contentLength;
				console.log(pro)
				this.setState({
					progressNum: pro,
				});
			}
		};

		try {
			const ret = RNFS.downloadFile(options);
			ret.promise.then(res => {
				console.log(res)
				this.setState({progressNum: 1})
			}).catch(err => {
				console.log('err', err);
			});
		}
		catch (e) {
			console.log(error);
		}
	}

this is my test code on IOS .I just tried progressDivider euqals to 10, still not work

chuhangyu avatar May 10 '18 07:05 chuhangyu

@chuhangyu +1 Not call progress if the file is not big

mark5566 avatar Dec 20 '19 07:12 mark5566

For anyone that reaches this issue, try the solution pointed here https://github.com/itinance/react-native-fs/issues/905

tironiigor avatar Mar 30 '22 22:03 tironiigor