最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to download image files in internal (App's private) storage react native - Stack Overflow

programmeradmin0浏览0评论

I am working on a react-native project in which I need to download some image files from the server and save them inside the App. These must be saved in the internal private storage of the App such that the app user must not be able to find these files (in non-rooted phone). I have searched on google and found the below options:

  1. Use AsyncStorage and save the image files in the Base64 string format. (I want to avoid this because this will add overhead [increase file size little bit] + unnecessary task of converting to/from base64)
  2. Use rn-fetch-blob library to directly fetch from/to the server in blob format but I unable to find the internal storage saving options. This options helps me to store files on Documents or Download etc but I need to store files in the internal memory.
  3. I can use URI as a source for all the images but I want to avoid dependency on the server as much as I can.

Please suggest a simple way to download image[ or other format] file in the react native app which must be inside App's private data folder without any conversion into string or any other medium.

I am working on a react-native project in which I need to download some image files from the server and save them inside the App. These must be saved in the internal private storage of the App such that the app user must not be able to find these files (in non-rooted phone). I have searched on google and found the below options:

  1. Use AsyncStorage and save the image files in the Base64 string format. (I want to avoid this because this will add overhead [increase file size little bit] + unnecessary task of converting to/from base64)
  2. Use rn-fetch-blob library to directly fetch from/to the server in blob format but I unable to find the internal storage saving options. This options helps me to store files on Documents or Download etc but I need to store files in the internal memory.
  3. I can use URI as a source for all the images but I want to avoid dependency on the server as much as I can.

Please suggest a simple way to download image[ or other format] file in the react native app which must be inside App's private data folder without any conversion into string or any other medium.

Share Improve this question asked Nov 26, 2018 at 10:51 Shubham1164Shubham1164 3576 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You can use Document Directory as path to save your files. It keeps the files inside the storage of application which you want and when you want to retrieve the files, then you already knows the base path and you just need to supply the filename to access the file.

const dirs = RNFetchBlob.fs.dirs; 
RNFetchBlob
  .config({
    path : dirs.DocumentDir + `${folder_name}/${filename}`
}).fetch('GET', `${fileURL}`).progress((received=0, total=0) => {
  //Handle progress of download here.. May be update UI...
}).then((resp) => {
   //You can get the path of the file saved using resp.path()
.catch((err) => {
  //Handle error here...                
});
发布评论

评论列表(0)

  1. 暂无评论