Download image from url on iOS React Native FS











up vote
0
down vote

favorite












I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:




/Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.




On real device, it's path (iPhone 8 Plus):




/var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg




I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;



because when i pick image from photo on real device this is path:




file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg




but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?



This is my code:



    downloadImage = () => {
// download(this.props.image.url, '_Subiz/image_' + this.props.image.name);

this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)

};


download = async (target, destination) => {
try{
let options = {
fromUrl: target,
toFile: destination,
begin: (res) => {
console.log(res)
},
progress: (data) => {
console.log(data)
},
background: true,
progressDivider: 1
};
console.log(options);
const request = await RNFS.downloadFile(options).promise
console.log(request)
}catch(e){
console.log(e)
}
};









share|improve this question




























    up vote
    0
    down vote

    favorite












    I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:




    /Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.




    On real device, it's path (iPhone 8 Plus):




    /var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg




    I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;



    because when i pick image from photo on real device this is path:




    file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg




    but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?



    This is my code:



        downloadImage = () => {
    // download(this.props.image.url, '_Subiz/image_' + this.props.image.name);

    this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)

    };


    download = async (target, destination) => {
    try{
    let options = {
    fromUrl: target,
    toFile: destination,
    begin: (res) => {
    console.log(res)
    },
    progress: (data) => {
    console.log(data)
    },
    background: true,
    progressDivider: 1
    };
    console.log(options);
    const request = await RNFS.downloadFile(options).promise
    console.log(request)
    }catch(e){
    console.log(e)
    }
    };









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:




      /Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.




      On real device, it's path (iPhone 8 Plus):




      /var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg




      I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;



      because when i pick image from photo on real device this is path:




      file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg




      but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?



      This is my code:



          downloadImage = () => {
      // download(this.props.image.url, '_Subiz/image_' + this.props.image.name);

      this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)

      };


      download = async (target, destination) => {
      try{
      let options = {
      fromUrl: target,
      toFile: destination,
      begin: (res) => {
      console.log(res)
      },
      progress: (data) => {
      console.log(data)
      },
      background: true,
      progressDivider: 1
      };
      console.log(options);
      const request = await RNFS.downloadFile(options).promise
      console.log(request)
      }catch(e){
      console.log(e)
      }
      };









      share|improve this question















      I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:




      /Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.




      On real device, it's path (iPhone 8 Plus):




      /var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg




      I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;



      because when i pick image from photo on real device this is path:




      file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg




      but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?



      This is my code:



          downloadImage = () => {
      // download(this.props.image.url, '_Subiz/image_' + this.props.image.name);

      this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)

      };


      download = async (target, destination) => {
      try{
      let options = {
      fromUrl: target,
      toFile: destination,
      begin: (res) => {
      console.log(res)
      },
      progress: (data) => {
      console.log(data)
      },
      background: true,
      progressDivider: 1
      };
      console.log(options);
      const request = await RNFS.downloadFile(options).promise
      console.log(request)
      }catch(e){
      console.log(e)
      }
      };






      ios react-native






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 11:37









      Milad Bahmanabadi

      585617




      585617










      asked Nov 12 at 8:16









      Hoàng Vũ Anh

      13812




      13812
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library



          const { fs } = RNFetchBlob;
          let Picture = fs.dirs.PictureDir;

          RNFetchBlob
          .config({
          appendExt : 'png',
          fileCache: true,
          path: Picture+(new Date()).getTime()+'.png',
          })
          .fetch('GET', 'image_url')
          .then((resp) => {
          // the image path you can use it directly with Image component
          console.log(resp.path());
          return resp.readFile('base64'); // If you get base64 file
          })
          .then((base64Data) => {
          console.log(base64Data);
          }).catch((errorMessage, statusCode) => {
          // error handling
          console.log('errorMessage2:'+errorMessage)
          });





          share|improve this answer























          • I try and it's not work. I can't see image in library on my iPhone. This is path after download done: =================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
            – Hoàng Vũ Anh
            Nov 13 at 3:45












          • check my updating answers
            – Yasin Ugurlu
            Nov 14 at 10:13










          • Thank for answer but Picture is undefined and it's not working
            – Hoàng Vũ Anh
            Nov 15 at 9:03










          • Are u sure define let Picture = fs.dirs.PictureDir;
            – Yasin Ugurlu
            Nov 15 at 13:07










          • Yes, of course, and it's undefined
            – Hoàng Vũ Anh
            Nov 16 at 2:15











          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',
          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%2f53258137%2fdownload-image-from-url-on-ios-react-native-fs%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








          up vote
          0
          down vote













          If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library



          const { fs } = RNFetchBlob;
          let Picture = fs.dirs.PictureDir;

          RNFetchBlob
          .config({
          appendExt : 'png',
          fileCache: true,
          path: Picture+(new Date()).getTime()+'.png',
          })
          .fetch('GET', 'image_url')
          .then((resp) => {
          // the image path you can use it directly with Image component
          console.log(resp.path());
          return resp.readFile('base64'); // If you get base64 file
          })
          .then((base64Data) => {
          console.log(base64Data);
          }).catch((errorMessage, statusCode) => {
          // error handling
          console.log('errorMessage2:'+errorMessage)
          });





          share|improve this answer























          • I try and it's not work. I can't see image in library on my iPhone. This is path after download done: =================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
            – Hoàng Vũ Anh
            Nov 13 at 3:45












          • check my updating answers
            – Yasin Ugurlu
            Nov 14 at 10:13










          • Thank for answer but Picture is undefined and it's not working
            – Hoàng Vũ Anh
            Nov 15 at 9:03










          • Are u sure define let Picture = fs.dirs.PictureDir;
            – Yasin Ugurlu
            Nov 15 at 13:07










          • Yes, of course, and it's undefined
            – Hoàng Vũ Anh
            Nov 16 at 2:15















          up vote
          0
          down vote













          If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library



          const { fs } = RNFetchBlob;
          let Picture = fs.dirs.PictureDir;

          RNFetchBlob
          .config({
          appendExt : 'png',
          fileCache: true,
          path: Picture+(new Date()).getTime()+'.png',
          })
          .fetch('GET', 'image_url')
          .then((resp) => {
          // the image path you can use it directly with Image component
          console.log(resp.path());
          return resp.readFile('base64'); // If you get base64 file
          })
          .then((base64Data) => {
          console.log(base64Data);
          }).catch((errorMessage, statusCode) => {
          // error handling
          console.log('errorMessage2:'+errorMessage)
          });





          share|improve this answer























          • I try and it's not work. I can't see image in library on my iPhone. This is path after download done: =================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
            – Hoàng Vũ Anh
            Nov 13 at 3:45












          • check my updating answers
            – Yasin Ugurlu
            Nov 14 at 10:13










          • Thank for answer but Picture is undefined and it's not working
            – Hoàng Vũ Anh
            Nov 15 at 9:03










          • Are u sure define let Picture = fs.dirs.PictureDir;
            – Yasin Ugurlu
            Nov 15 at 13:07










          • Yes, of course, and it's undefined
            – Hoàng Vũ Anh
            Nov 16 at 2:15













          up vote
          0
          down vote










          up vote
          0
          down vote









          If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library



          const { fs } = RNFetchBlob;
          let Picture = fs.dirs.PictureDir;

          RNFetchBlob
          .config({
          appendExt : 'png',
          fileCache: true,
          path: Picture+(new Date()).getTime()+'.png',
          })
          .fetch('GET', 'image_url')
          .then((resp) => {
          // the image path you can use it directly with Image component
          console.log(resp.path());
          return resp.readFile('base64'); // If you get base64 file
          })
          .then((base64Data) => {
          console.log(base64Data);
          }).catch((errorMessage, statusCode) => {
          // error handling
          console.log('errorMessage2:'+errorMessage)
          });





          share|improve this answer














          If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library



          const { fs } = RNFetchBlob;
          let Picture = fs.dirs.PictureDir;

          RNFetchBlob
          .config({
          appendExt : 'png',
          fileCache: true,
          path: Picture+(new Date()).getTime()+'.png',
          })
          .fetch('GET', 'image_url')
          .then((resp) => {
          // the image path you can use it directly with Image component
          console.log(resp.path());
          return resp.readFile('base64'); // If you get base64 file
          })
          .then((base64Data) => {
          console.log(base64Data);
          }).catch((errorMessage, statusCode) => {
          // error handling
          console.log('errorMessage2:'+errorMessage)
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 at 10:12

























          answered Nov 12 at 13:59









          Yasin Ugurlu

          15217




          15217












          • I try and it's not work. I can't see image in library on my iPhone. This is path after download done: =================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
            – Hoàng Vũ Anh
            Nov 13 at 3:45












          • check my updating answers
            – Yasin Ugurlu
            Nov 14 at 10:13










          • Thank for answer but Picture is undefined and it's not working
            – Hoàng Vũ Anh
            Nov 15 at 9:03










          • Are u sure define let Picture = fs.dirs.PictureDir;
            – Yasin Ugurlu
            Nov 15 at 13:07










          • Yes, of course, and it's undefined
            – Hoàng Vũ Anh
            Nov 16 at 2:15


















          • I try and it's not work. I can't see image in library on my iPhone. This is path after download done: =================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
            – Hoàng Vũ Anh
            Nov 13 at 3:45












          • check my updating answers
            – Yasin Ugurlu
            Nov 14 at 10:13










          • Thank for answer but Picture is undefined and it's not working
            – Hoàng Vũ Anh
            Nov 15 at 9:03










          • Are u sure define let Picture = fs.dirs.PictureDir;
            – Yasin Ugurlu
            Nov 15 at 13:07










          • Yes, of course, and it's undefined
            – Hoàng Vũ Anh
            Nov 16 at 2:15
















          I try and it's not work. I can't see image in library on my iPhone. This is path after download done: =================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
          – Hoàng Vũ Anh
          Nov 13 at 3:45






          I try and it's not work. I can't see image in library on my iPhone. This is path after download done: =================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
          – Hoàng Vũ Anh
          Nov 13 at 3:45














          check my updating answers
          – Yasin Ugurlu
          Nov 14 at 10:13




          check my updating answers
          – Yasin Ugurlu
          Nov 14 at 10:13












          Thank for answer but Picture is undefined and it's not working
          – Hoàng Vũ Anh
          Nov 15 at 9:03




          Thank for answer but Picture is undefined and it's not working
          – Hoàng Vũ Anh
          Nov 15 at 9:03












          Are u sure define let Picture = fs.dirs.PictureDir;
          – Yasin Ugurlu
          Nov 15 at 13:07




          Are u sure define let Picture = fs.dirs.PictureDir;
          – Yasin Ugurlu
          Nov 15 at 13:07












          Yes, of course, and it's undefined
          – Hoàng Vũ Anh
          Nov 16 at 2:15




          Yes, of course, and it's undefined
          – Hoàng Vũ Anh
          Nov 16 at 2:15


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53258137%2fdownload-image-from-url-on-ios-react-native-fs%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

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?