base64 메모리로 다운로드

설명
Tags
download
base64

파일 다운로드 (메모리, base64)

  • 가장 심플한 방법이 메모리에 BASE64 로 인코딩된 문자열로 다운로드하는 것이다.
  • 응답 데이터 크기가 작을 때 유용하다.
// 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 .. }) .then((res) => { let status = res.info().status; if(status == 200) { // 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() } else { // handle other status codes } }) // Something went wrong: .catch((errorMessage, statusCode) => { // error handling })