-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress not working in version 17.0.0 and higher #248
Comments
Hi, thanks for using the lib and your report. |
Thanks for the reply, Ron! I've tested on iOS, didn't get to test it on android Heres the code snippet: import { Platform } from 'react-native';
import RNFetchBlob from 'react-native-blob-util';
import { Observable } from 'rxjs';
import { IDownloadTaskProps } from './types';
import {
COMPLETED_DOWNLOAD_STATUS,
COMPLETED_DOWNLOAD_PROGRESS,
DEFAULT_CONFIG,
DOWNLOAD_IN_PROGRESS_STATUS,
TOTAL_PERCENT,
DIR_NAME,
} from './constants';
import { ITaskObservable } from '@/modules/download/types';
export const downloadTask = (data: IDownloadTaskProps): ITaskObservable => {
const {
fs: { dirs },
config,
} = RNFetchBlob;
const rootDir = dirs[Platform.OS === 'ios' ? 'DocumentDir' : 'DownloadDir'];
const path = `${rootDir}/${DIR_NAME}/${data?.fileName}`;
return new Observable((observer) => {
const downloadProgress = (received: number, total: number) => {
const progress = Math.round((received / total) * TOTAL_PERCENT);
observer.next({
status: DOWNLOAD_IN_PROGRESS_STATUS,
progress,
taskId: data.taskId,
contentData: undefined,
});
};
try {
const response = config({
...(data.configOptions ?? DEFAULT_CONFIG),
path,
}).fetch(data.fetchMethod, data.fileUrl);
response
.progress(downloadProgress)
.then((res) => {
observer.next({
status: COMPLETED_DOWNLOAD_STATUS,
progress: COMPLETED_DOWNLOAD_PROGRESS,
taskId: data?.taskId,
contentData: res,
});
observer.complete();
})
.catch((err) => {
observer.error(`Error while trying to download: ${err}`);
});
} catch (error) {
observer.error(`Error while trying to write file: ${error}`);
}
});
}; |
Same issue here on iOS v 17.3 |
Do you get the status and headers of the request set correctly? |
Hi guys!
I've implemented a download function in my react native project using the latest version of react-native-blob-util, but the progress callback was never being called
I got to make it work out by downgrading the library version to 16.4.0, but the latest version really doesn't work. I want to be able to use the latest versions, can you help me? 🙌
The text was updated successfully, but these errors were encountered: