ファイルをダウンロードする際のサンプル
https://github.com/wkh237/react-native-fetch-blob#download-example-fetch-files-that-need-authorization-token
// send http request in a new thread (using native code)
RNFetchBlob.fetch('GET', 'http://www.example.com/images/img1.png', {
Authorization : 'Bearer access-token...',
// more headers ..
})
// when response status code is 200
.then((res) => {
// the conversion is done in native code
let base64Str = res.base64()
// the following conversions are done in js, it's SYNC
let text = res.text()
let json = res.json()
})
// Status code is not 200
.catch((errorMessage, statusCode) => {
// error handling
})
で catch に来るのはレスポンスのステータスコードが200以外の場合と書いてありますが、これは誤りです。
ネットワークエラーなどの場合にのみ catch句に来るようになり、サーバーから何らかのレスポンスがあった際にはthenの方に処理が入ります。
ステータスコードでチェックする場合には以下のようにして分岐をします。
.then((res) => {
const status = Math.floor(res.info().status);
if (status === 200) {
//ここで処理を行う
} else {
throw new Error('200以外のステータスが返ってきた場合の処理');
}
})
res.info().statusにレスポンスのステータスが返ってきます。数字型にして比較したいので、Math.floor をかましています。
参考
https://github.com/wkh237/react-native-fetch-blob/issues/267
https://github.com/wkh237/react-native-fetch-blob/issues/131


