Я использую expo-file-system для создания возобновляемой загрузки.Я использую тот же пример, что и в документации выставки.
https://docs.expo.io/versions/latest/sdk/filesystem/
Часть загрузки работает хорошо.Он загружает файл и дает прогресс на этом пути.Но когда я пытаюсь использовать функцию pauseAsync, она выдает ошибку.
'Объект загрузки недоступен'
export default function App() {
const [downloadProgress,setDownloadProgress] = useState({})
const callback = downloadProgress => {
const progress = downloadProgress.totalBytesWritten / downloadProgress.totalBytesExpectedToWrite;
console.log(progress);
setDownloadProgress(progress)
};
const downloadResumable = FileSystem.createDownloadResumable(
'http://techslides.com/demos/sample-videos/small.mp4',
FileSystem.documentDirectory + 'small.mp4',
{},
callback
);
startDownload = async() =>{
try {
const { uri } = await downloadResumable.downloadAsync();
console.log('Finished downloading to ', uri);
} catch (e) {
console.error(e);
}
}
pauseDownload = async() =>{
try {
await downloadResumable.pauseAsync();
console.log('Paused download operation, saving for future retrieval');
AsyncStorage.setItem('pausedDownload', JSON.stringify(downloadResumable.savable()));
} catch (e) {
console.error(e);
}
}
return (
<View style={{ flex: 1,backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',marginTop: 20}}>
<TouchableNativeFeedback onPress = {this.startDownload}>
<View style={{alignItems:'center',justifyContent:'center',height:50,width:100,backgroundColor:'#00f',marginBottom:2}}>
<Text style={{color:'#fff'}}>Download</Text>
</View>
</TouchableNativeFeedback>
<TouchableNativeFeedback onPress = {this.pauseDownload}>
<View style={{alignItems:'center',justifyContent:'center',height:50,width:100,backgroundColor:'#00f',marginBottom:2}}>
<Text style={{color:'#fff'}}>Pause</Text>
</View>
</TouchableNativeFeedback>
</View>
);
}
Это ошибка, которую я получаю. Ошибка изображения здесь