如何下载图像并将其保存到本地应用程序中的反应本地应用程序

问题描述:

它似乎像提取没有在图像下载工作。如何下载图像并将其保存到本地应用程序中的反应本地应用程序

fetch("url to image").then((resp) => { 
 
    return resp.blob(); 
 
})

+0

我可以知道为什么你想将图像保存在localStorage中? – Jickson

+0

我想缓存它。而不是每次启动应用时都要求提供。 –

尝试RNFS,它可以正确地下载文件到本地目录中,做到这一点,但我有问题,与显示此图像OMG

RNFS.downloadFile({ 
    fromUrl: string;   // URL to download file from 
    toFile: string;   // Local filesystem path to save the file to 
    headers?: Headers;  // An object of headers to be passed to the server 
    background?: boolean; 
    progressDivider?: number; 
    begin?: (res: DownloadBeginCallbackResult) => void; 
    progress?: (res: DownloadProgressCallbackResult) => void; 
} 

你可以检查文件是否是已下载:

RNFS.exists(ICON).then(function(file){ 
    if(!file){ 
     RNFS.downloadFile({ 
     fromUrl: 'string', 
     toFile : 'string' 
    }).catch(function(e){console.log(e)}) 
    } 
}).catch(function(e){console.log(e)})