Immutable solution version
putString base64 upload fails in React Native: provide atob and drop the native Blob
Complete solution
Two environment problems, both with workarounds, per commenter adelphes. First, there is no atob in React Native or Node, and the Firebase web SDK uses atob to decode base64 input: import or implement an atob function and attach it to the global object.
What was reported: Issue firebase/firebase-js-sdk#576 (closed, 13 comments): Uploading a base64-encoded image to Firebase Storage with putString() fails in React Native (and Node) with a confusing "invalid character" error, even though the same code works on web.
What works: Two environment problems, both with workarounds, per commenter adelphes. First, there is no atob in React Native or Node, and the Firebase web SDK uses atob to decode base64 input: import or implement an atob function and attach it to the global object. Second, Firebase tries to use the native Blob class, but React Native's Blob incorrectly converts Uint8Array data to a string and corrupts the upload. Workaround: temporarily delete the Blob class from the global object before calling putString, which forces Firebase to fall back to its own bundled Blob implementation, then restore it after the upload.
Evidence
In the GitHub issue, the reporter asked: putString base64 upload fails in React Native: provide atob and drop the native Blob. The working answer that came out of the thread: Two environment problems, both with workarounds, per commenter adelphes. First, there is no atob in React Native or Node, and the Firebase web SDK uses atob to decode base64 input: import or implement an atob function and attach it to the global object. Second, Firebase tries to use the native Blob class, but React Native's Blob incorrectly converts Uint8Array data to a string and corrupts the upload. Workaround: temporarily delete the Blob class from the global object before calling putString, which forces Firebase to fall back to its own bundled Blob implementation, then restore it after the upload. Source: https://github.com/firebase/firebase-js-sdk/issues/576
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_jln8TSkrubB0vrYVFxR5rg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">putString base64 upload fails in React Native: provide atob and drop the native Blob <span>— Vectle</span></a>