Unable to upload a PDF file to Firebase Storage (RNFirebase) using react-native

I need to upload the pdf file to firebase storage. I am able to retrieve the URI of the document using react-native-document-picker. However, I am receiving errors while making a blob or converting the doc file to base64.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// One approach of converting doc file to base 64. It converts it but fails when trying to upload // it to the storage giving "NativeFirebaseError: [storage/unknown]" error.
async handleURIConversionToBase64(uri) {
return RNFS.readFile(uri, 'base64').then(base64String =>
base64String
).catch(error => {
console.log('error while RNFS: ', error);
});
}
// Another approach of making a blob is giving me "RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]." error.
async getBlob(uri) {
return fetch(uri).then(response => {
return response.blob().then(blobFile => {
return blobFile;
}).catch(error => {
console.log('error while blobbing: ', error);
});
}).catch(error => {
console.log('error while fetching: ', error);
});
}
</code>
<code>// One approach of converting doc file to base 64. It converts it but fails when trying to upload // it to the storage giving "NativeFirebaseError: [storage/unknown]" error. async handleURIConversionToBase64(uri) { return RNFS.readFile(uri, 'base64').then(base64String => base64String ).catch(error => { console.log('error while RNFS: ', error); }); } // Another approach of making a blob is giving me "RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]." error. async getBlob(uri) { return fetch(uri).then(response => { return response.blob().then(blobFile => { return blobFile; }).catch(error => { console.log('error while blobbing: ', error); }); }).catch(error => { console.log('error while fetching: ', error); }); } </code>
// One approach of converting doc file to base 64. It converts it but fails when trying to upload // it to the storage giving "NativeFirebaseError: [storage/unknown]" error.
async handleURIConversionToBase64(uri) {
    return RNFS.readFile(uri, 'base64').then(base64String =>
      base64String


    ).catch(error => {
      console.log('error while RNFS: ', error);
    });
  }

// Another approach of making a blob is giving me "RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]." error.
  async getBlob(uri) {
    return fetch(uri).then(response => {
      return response.blob().then(blobFile => {
        return blobFile;
      }).catch(error => {
        console.log('error while blobbing: ', error);
      });
    }).catch(error => {
      console.log('error while fetching: ', error);
    });
  }
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// This is what I have tried so far. I have used stringDecodedURI and stringDecodedURIComponent // interchangeably but of no use. Also, I have used handleURIConversionToBase64 and getBlob but // nothing helped.
const stringDecodedURI = decodeURI(uri);
const stringDecodedURIComponent = decodeURIComponent(uri);
this.getBlob(`${stringDecodedURIComponent}/${fileName}`).then(blob => {
const storageRef = storage.ref(JobAssets.getStorageRefString(orgID, newJobAssetID));
const unsubscribe = storageRef.putFile(blob).on('state_changed',
snapshot => {
const progressNumber = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
const progress = progressNumber.toString().slice(0, 4);
this.setState({ progress });
},
err => {
console.log('error 1: ', err);
reject(err);
unsubscribe();
},
() => {
const url = storageRef.getDownloadURL();
console.log('url');
resolve(url);
this.setState({ fileUploading: false });
unsubscribe();
}
);
});
</code>
<code>// This is what I have tried so far. I have used stringDecodedURI and stringDecodedURIComponent // interchangeably but of no use. Also, I have used handleURIConversionToBase64 and getBlob but // nothing helped. const stringDecodedURI = decodeURI(uri); const stringDecodedURIComponent = decodeURIComponent(uri); this.getBlob(`${stringDecodedURIComponent}/${fileName}`).then(blob => { const storageRef = storage.ref(JobAssets.getStorageRefString(orgID, newJobAssetID)); const unsubscribe = storageRef.putFile(blob).on('state_changed', snapshot => { const progressNumber = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; const progress = progressNumber.toString().slice(0, 4); this.setState({ progress }); }, err => { console.log('error 1: ', err); reject(err); unsubscribe(); }, () => { const url = storageRef.getDownloadURL(); console.log('url'); resolve(url); this.setState({ fileUploading: false }); unsubscribe(); } ); }); </code>
// This is what I have tried so far. I have used stringDecodedURI and stringDecodedURIComponent // interchangeably but of no use. Also, I have used handleURIConversionToBase64 and getBlob but // nothing helped.

const stringDecodedURI = decodeURI(uri);
const stringDecodedURIComponent = decodeURIComponent(uri);
this.getBlob(`${stringDecodedURIComponent}/${fileName}`).then(blob => {
const storageRef = storage.ref(JobAssets.getStorageRefString(orgID, newJobAssetID));
const unsubscribe = storageRef.putFile(blob).on('state_changed',
                snapshot => {
                  const progressNumber = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
                  const progress = progressNumber.toString().slice(0, 4);
                  this.setState({ progress });
                },
                err => {
                  console.log('error 1: ', err);
                  reject(err);
                  unsubscribe();
                },
                () => {
                  const url = storageRef.getDownloadURL();
                  console.log('url');
                  resolve(url);
                  this.setState({ fileUploading: false });
                  unsubscribe();
                }
              );
            });

Any help would be appreciated. TIA!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật