2017-10-02 7 views
0

私はダウンロードイメージにreact-native-fetch-blobを使用しています。イメージのダウンロード速度を改善するにはどうすればよいですか?

私のソースコードです。

downloadThumb(element) { 
    return new Promise((resolve, reject) => { 
     RNFetchBlob.config({ 
     // add this option that makes response data to be stored as a file, 
     // this is much more performant. 
     fileCache: true, 
     path: `${DocumentDirectoryPath}/thumbs/${element}`, 
     }) 
     .fetch(
      'GET', 
      `https://www.searchforsites.co.uk/images/thumbs/${element}`, 
      { 
      // some headers .. 
      }, 
     ) 
     .then((res) => { 
      resolve(true); 
     }) 
     .catch((err) => { 
      // console.log('Error: ', err); 
      // this.setState({ modalOpen: false, regionUpdated: true }); 
      // this.findUser(); 
      reject(true); 
     }); 
    }); 
    } 

/////////////////////////////////////// 
    recursive_thumb(element) { 
    this.downloadThumb(element).then((response) => { 
     if (this.state.count > this.state.total_thumbs) { 
     this.setState({ modalOpen: false }); 
     setThumbDownloaded(); 
     return true; 
     } 
     this.state.count += 1; 
     // console.log(this.state.count); 
     this.setState({ totalCount: this.state.total_thumbs, fetchedCount: this.state.count }); 
     this.recursive_thumb(this.state.thumbs[this.state.count]); 
    }); 
    } 

ファイルサイズは約8KBです。今私はひとつずつドローロードしています。 1枚の画像(8KB)をダウンロードするのに1秒かかります。

ダウンロード速度を改善するソリューションはありますか?

お時間をいただきありがとうございます。

答えて

1

あなたは一連の画像のダウンロードを増加したい場合:https://github.com/jaydson/es7-async

: ちょうどすべての並列

Promise.all([ 
    downloadThumb('data.jpeg'), 
    downloadThumb('users.jpeg'), 
    downloadThumb('products.jpeg') 
]) 
.then(function(data) { 
    console.log('Parallel promises >>>', data); 
}); 

このgithubのページをチェックアウトして取得しますPromise.allを作成します

関連する問題