Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const RNFS = require('react-native-fs');
  2. const dirHome = Platform.select({
  3.   ios: `${RNFS.DocumentDirectoryPath}/Pictures/OutletClassification`,
  4.   android: `${RNFS.ExternalStorageDirectoryPath}/Pictures/OutletClassification`
  5. });
  6.  
  7. const dirPicutures = `${dirHome}/Pictures`;
  8. const downloadFile = async (url, newFilepath) => {
  9.   console.log('process moved')
  10.   return new Promise((resolve, reject) => {
  11.     RNFS.mkdir(dirPicutures)
  12.       .then(() => {
  13.         RNFS.downloadFile({fromUrl:url, toFile: newFilepath}).promise.then(res => {
  14.           console.log('Download result', res)
  15.           this.setState({ downloaded: true });
  16.         });
  17.       })
  18.       .catch(err => {
  19.         console.log('mkdir error', err);
  20.         reject(err);
  21.       });
  22.   });
  23. };
  24.  
  25. ==========
  26. itemPhoto.reduce(async (result,val) =>{
  27.           console.log('loop photo', val)
  28.           const url = this.state.url+val.picture;
  29.           const newImageName = `${Moment().format('DDMMYY_HHmmssSSS')}.jpg`;
  30.           const newFilepath = `${dirPicutures}/${newImageName}`;
  31.  
  32.           arrItemPhoto.push({
  33.             id: xItem + 1,
  34.             picture: newFilepath,
  35.           })
  36.           xItem++;
  37.           const download = await downloadFile(url, newFilepath);
  38.          
  39.         },{})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement