UploadForm.js
import { AsyncStorage } from 'react-native'; import React, { Component } from 'react'; import axios from 'axios'; import * as FileSystem from "expo-file-system"; import * as Permissions from 'expo-permissions'; import * as MediaLibrary from 'expo-media-library'; export const api = axios.create({ baseURL: 'https://programmerdesign.com/yonfile', }) export const options = { headers, } export const headers = { 'Content-Type': 'application/json' } class UploadForm extends Component { constructor(props) { super(props); } onDownloadFile= async (data) => { await AsyncStorage.getItem('token') .then(async (value) => { const response = await api.get("/transaction/get_file_path?id=" + data.id + "&access-token=" + value, options); const downloadResumable = FileSystem.createDownloadResumable( "https://programmerdesign.com" + response.data.data, FileSystem.documentDirectory + data.file_name, ); const { uri } = await downloadResumable.downloadAsync(); this.downloadfile(uri); }); } downloadfile = async(uri) => { try { const perm = await Permissions.askAsync(Permissions.CAMERA_ROLL); if (perm.status == 'granted') { try { const asset = await MediaLibrary.createAssetAsync(uri); const album = await MediaLibrary.getAlbumAsync('Download'); if (album == null) { await MediaLibrary.createAlbumAsync('Download', asset, false); } else { await MediaLibrary.addAssetsToAlbumAsync([asset], album, false); } alert("Download complete") } catch (e) { throw new Error("Media Library not Create Asset") } } } catch (e) { throw new Error("Media Library permission not granted") } } render() { return ( <View></View>); } } export default UploadForm;