Untitled
unknown
plain_text
a year ago
1.6 kB
1
Indexable
const downloadToLocal = async (fileUrl, callback = null) => { if (Platform.OS === "android" && !(await hasAndroidPermission())) { return; } setIsDownloading(true); setProgressValue(0) const outputPath = `${dirs}/${fileKey}_${fileUrl.substring(fileUrl.lastIndexOf('/') + 1, fileUrl.length)}`; RNFetchBlob.config({ fileCache: true, appendExt: 'jpg', path: outputPath }) .fetch('GET', fileUrl) .progress((received, total) => { // console.log("progress", received / total); setProgressValue(received / total); }) .then(async (res) => { setIsDownloading(false) // setLocalThumbnail(`file://${outputPath}`); if (callback) { callback(`file://${outputPath}`); } }) .catch(error => { console.log(error) Toast.show({ type: 'error', text1: 'Network Error', text2: 'Cannot load video.' }) if (callback) { callback(null); } }).finally(() => { setTimeout(() => { setIsDownloading(false); }, 500) if (callback) { callback(); } }) }
Editor is loading...
Leave a Comment