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












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.










share|improve this question



























    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.










    share|improve this question

























      0












      0








      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.










      share|improve this question














      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.







      javascript android ios react-native






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 10:51









      Shubham1164Shubham1164

      6817




      6817
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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...
          });


          Hope this helps. Happy coding :)






          share|improve this answer
























          • Can the app user see my files here?

            – Shubham1164
            Nov 26 '18 at 11:20











          • No apparently. In iOS a strict NO, and in android, it can be viewed by hacking the way via the android/data/appid/data/obb and all..... if you are getting what i am trying to specify. But thats all that the other apps does. If you need some kind of encryption then you have to manually encrypt and decrypt the file before saving and after fetching.

            – Suraj Malviya
            Nov 26 '18 at 11:32








          • 1





            Yes. Thanks Suraj.

            – Shubham1164
            Nov 26 '18 at 11:34











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479538%2fhow-to-download-image-files-in-internal-apps-private-storage-react-native%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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...
          });


          Hope this helps. Happy coding :)






          share|improve this answer
























          • Can the app user see my files here?

            – Shubham1164
            Nov 26 '18 at 11:20











          • No apparently. In iOS a strict NO, and in android, it can be viewed by hacking the way via the android/data/appid/data/obb and all..... if you are getting what i am trying to specify. But thats all that the other apps does. If you need some kind of encryption then you have to manually encrypt and decrypt the file before saving and after fetching.

            – Suraj Malviya
            Nov 26 '18 at 11:32








          • 1





            Yes. Thanks Suraj.

            – Shubham1164
            Nov 26 '18 at 11:34
















          1














          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...
          });


          Hope this helps. Happy coding :)






          share|improve this answer
























          • Can the app user see my files here?

            – Shubham1164
            Nov 26 '18 at 11:20











          • No apparently. In iOS a strict NO, and in android, it can be viewed by hacking the way via the android/data/appid/data/obb and all..... if you are getting what i am trying to specify. But thats all that the other apps does. If you need some kind of encryption then you have to manually encrypt and decrypt the file before saving and after fetching.

            – Suraj Malviya
            Nov 26 '18 at 11:32








          • 1





            Yes. Thanks Suraj.

            – Shubham1164
            Nov 26 '18 at 11:34














          1












          1








          1







          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...
          });


          Hope this helps. Happy coding :)






          share|improve this answer













          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...
          });


          Hope this helps. Happy coding :)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 11:08









          Suraj MalviyaSuraj Malviya

          855414




          855414













          • Can the app user see my files here?

            – Shubham1164
            Nov 26 '18 at 11:20











          • No apparently. In iOS a strict NO, and in android, it can be viewed by hacking the way via the android/data/appid/data/obb and all..... if you are getting what i am trying to specify. But thats all that the other apps does. If you need some kind of encryption then you have to manually encrypt and decrypt the file before saving and after fetching.

            – Suraj Malviya
            Nov 26 '18 at 11:32








          • 1





            Yes. Thanks Suraj.

            – Shubham1164
            Nov 26 '18 at 11:34



















          • Can the app user see my files here?

            – Shubham1164
            Nov 26 '18 at 11:20











          • No apparently. In iOS a strict NO, and in android, it can be viewed by hacking the way via the android/data/appid/data/obb and all..... if you are getting what i am trying to specify. But thats all that the other apps does. If you need some kind of encryption then you have to manually encrypt and decrypt the file before saving and after fetching.

            – Suraj Malviya
            Nov 26 '18 at 11:32








          • 1





            Yes. Thanks Suraj.

            – Shubham1164
            Nov 26 '18 at 11:34

















          Can the app user see my files here?

          – Shubham1164
          Nov 26 '18 at 11:20





          Can the app user see my files here?

          – Shubham1164
          Nov 26 '18 at 11:20













          No apparently. In iOS a strict NO, and in android, it can be viewed by hacking the way via the android/data/appid/data/obb and all..... if you are getting what i am trying to specify. But thats all that the other apps does. If you need some kind of encryption then you have to manually encrypt and decrypt the file before saving and after fetching.

          – Suraj Malviya
          Nov 26 '18 at 11:32







          No apparently. In iOS a strict NO, and in android, it can be viewed by hacking the way via the android/data/appid/data/obb and all..... if you are getting what i am trying to specify. But thats all that the other apps does. If you need some kind of encryption then you have to manually encrypt and decrypt the file before saving and after fetching.

          – Suraj Malviya
          Nov 26 '18 at 11:32






          1




          1





          Yes. Thanks Suraj.

          – Shubham1164
          Nov 26 '18 at 11:34





          Yes. Thanks Suraj.

          – Shubham1164
          Nov 26 '18 at 11:34




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479538%2fhow-to-download-image-files-in-internal-apps-private-storage-react-native%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Futebolista

          Jornalista