[1] tmp 파일로 다운로드
- 반환 데이터 크기가 클 경우에는 BASE64 문자열로 변환시키는 것보다 파일로 저장하는 것이 권장됨.
config
에서fileCache
옵션을true
로 설정하면 된다.
- response data를 임시파일저장경로에 확장자 없이 저장된다.
- 이 파일은 자동으로 삭제되지 않으므로, Cache File Management룰 참고하자

RNFetchBlob .config({ // add this option that makes response data to be stored as a file, // this is much more performant. fileCache : true, }) .fetch('GET', 'http://www.example.com/file/example.zip', { //some headers .. }) .then((res) => { // the temp file path console.log('The file saved to ', res.path()) })
[2] 확장자 추가하기
Image
컴포넌트에서 사용하려면 확장자가 있어야함.따라서 '
png
', 'jpg
' 등 확장자를 붙여서 저장하도록 설정해서 쓰면 됨.
RNFetchBlob .config({ fileCache : true, // by adding this option, the temp files will have a file extension appendExt : 'png' }) .fetch('GET', 'http://www.example.com/file/example.zip', { //some headers .. }) .then((res) => { // the temp file path with file extension `png` console.log('The file saved to ', res.path()) // Beware that when using a file path as Image source on Android, // you must prepend "file://"" before the file path imageView = <Image source={{ uri : Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path() }}/> })
[3] 원하는 경로에 저장하기 (앱 샌드박스 내에서)
config
에path
옵션으로 '경로/파일명
' 을 작성하면 됨.- 이 옵션을 설정하면 원하는
경로/파일명.확장자
를 직접 명시할 수 있다. - 이 옵션을 설정하면
fileCache
와appendExt
옵션은 무시된다.
- 단 서드파티 앱의 경우 앱 샌드박스를 벗어날 수는 없으므로, 가능한 경로는 샌드박스 내로 한정된다

경로와 관련된 constants

예시 코드
let dirs = RNFetchBlob.fs.dirs; RNFetchBlob .config({ // response data will be saved to this path if it has access right. path : dirs.DocumentDir + '/path-to-file.anything' }) .fetch('GET', 'http://www.example.com/file/example.zip', { //some headers .. }) .then((res) => { // the path should be dirs.DocumentDir + 'path-to-file.anything' console.log('The file saved to ', res.path()) })