Front-end/React & React Native

React Native 파일 다운로드 구현 (rn-fetch-blob VS react-native-fs)

대런대런 2020. 11. 17. 16:55
반응형

React Native에서 간단한 파일 다운로드를 구현할 일이 있어 패키지를 검색하던중 가장 star가 많은 두 패키지를 비교하였다.

 

npm trend 비교

www.npmtrends.com/react-native-fs-vs-rn-fetch-blob

 

react-native-fs (star 3.8k, 오래됨)

import RNFS from 'react-native-fs';

const download = async (file: File) => {
  const downloadDest = `${RNFS.DocumentDirectoryPath}/${file.name}`;
  const {promise} = RNFS.downloadFile({
    fromUrl: BACKEND_URL + file.url,
    toFile: downloadDest,
  });
  const {statusCode} = await promise;
};

 

rn-fetch-blob (star 2.2k, 안드로이드 다운로드 매니저 지원)

import RNFetchBlob from 'rn-fetch-blob';

const download = async (file: File) => {
  await RNFetchBlob.config({
    addAndroidDownloads: {
      useDownloadManager: true,
      notification: true,
      path: `${RNFetchBlob.fs.dirs.DownloadDir}/${file.name}`,
    },
  }).fetch('GET', BACKEND_URL + file.url);
};

 

둘다 잘 다운로드 되지만, 안드로이드 다운로드 매니저를 통하는 방식을 지원하는건 rn-fetch-blob만 가능하여 이 패키지로 선택하였다.

반응형