progress not work when downloadFile
version: "react-native-fs": "2.13.3" platform: iOS
code:
let documentPath = RNFS.DocumentDirectoryPath;
let zipPath = documentPath+'/app.zip'
let options = {
fromUrl: downLoadUrl,
toFile: zipPath,
background: true,
progressDivider: 5,
discretionary: true,
cacheable: true,
begin: (res) => {
console.log('begin', res);
},
progress: (res) => {
console.log('progress', res)
}
}
let ret = RNFS.downloadFile(options);
ret.promise.then(res=>{
console.log('====================================');
console.log('complete',res);
console.log('====================================');
}).catch(err=>{
console.log(err);
})
问题找到了, iOS原生代码,Downloader.m文件中,有判断,如果[_statusCode isEqualToNumber:[NSNumber numberWithInt:200]]才会进入进度更新的回调. 其它一概不接受.我们服务端返回的是_statusCode 等于 201.
I think it is necessary to fix this problem.
@xclidongbo it looks like when I provide begin callback together with progress (even when begin is noop function), then progress is working correctly again.
Can you check?
@sebinq you saved my day, thanks!
mine too! thanks @sebinq but funny, I remember this working without begin
@LuisRodriguezLD yep, it was working before just fine. I don't know what what has changed :D But it is good that there is this hack which make it works again.
@sebqq Thanks !, Saved my evening :-p
Glad to help 🍻
Thanks @sebqq for your awesome help.
I don't know why still it isn't fixed, by using a default noop function this issue would be fixed.
Facing the same issue right now with progress not working with uploading files. Can anyone please help. I have added the begin callback as well:
const fields = {
"x-goog-date": credentials.x_goog_date,
"success_action_status": credentials.success_action_status,
"x-goog-algorithm": credentials.x_goog_algorithm,
"content-encoding": credentials.content_encoding,
"x-goog-credential": credentials.x_goog_credential,
"acl": credentials.acl,
"key": credentials.key,
"x-goog-signature": credentials.x_goog_signature,
"policy": credentials.policy,
"x-goog-meta-uid": credentials.x_goog_meta_uid,
"x-goog-meta-filename": credentials.x_goog_meta_filename,
};
try {
const uploadOptions = {
toUrl: url,
files: [{
name: 'file',
filename: filename,
filepath: imageData.sourceURL.replace('file://', ''),
filetype: imageData.mime,
}],
method: 'POST',
fields: fields,
begin: (response: any) => {
console.log('upload started')
},
progress: (response: any) => {
console.log('response.totalBytesSent: ', response.totalBytesSent);
console.log('response.totalBytesExpectedToSend: ', response.totalBytesExpectedToSend);
}
};
const result = await RNFS.uploadFiles(uploadOptions).promise;
} catch (error: any) {
console.log('Error: ', error.message, error.response?.data);
}
upload started is logging fine but the progress callback is not being triggered. Does anyone know the solution I have exhausted everything.
Edit: File upload is also being done successfully. No errors in that.