question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for React Native blob

See original GitHub issue

I’ve seen many people complaining about issues when uploading files with React Native. The best solution today is to use fetch() which supports the blob generated in React Native, but it lacks progress. Libs such as rn-fetch-blob can’t be used in Expo since you’d need to eject.

Many libraries for React Native such as Firebase have upload method that has support for the React Native blob and it would be a great addition to Axios as well.

What I’d like to do is basically:

await Axios.post(url, reactNativeBlob, ...)

I’ve tried different methods with Axios, e.g. by creating FormData with the file details, such as uri, name and type, but then Axios tries to convert the file to base64 and upload it that way, which isn’t what I want.

I don’t know how React Native blobs are different from web blobs, but I’m really hoping that this could be supported in Axios.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
chinesedfancommented, Sep 12, 2020

Axios won’t support it directly. But if someone finished it in a wrapper package, we can record it in our ECOSYSTEM.md.

5reactions
jamesaucodecommented, May 20, 2021

If anyone is still having trouble with working with React Native’s blob and axios, here’s a temporary work around that I have.

class RNBlob extends Blob {
  get [Symbol.toStringTag]() {
    return 'Blob';
  }
}

// then on the blob that you want to work with
axios.post('api', {
  data: new RNBlob([blob])
});

Because of how Axios determine whether an object is a blob (see: utils#147), it does a Object.prototype.call on the request body, but on React Native, calling Object.prototype.call on Blob returns [object Object] instead of [object Blob], so axios will simply JSON.stringify it as if it’s a generic javascript object. The above snippet will ‘trick’ axios into thinking it’s a Blob (which it is), and process it correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native-blob-util - npm
A module provides upload, download, and files access API. Supports file stream read/write for process large files.. Latest version: 0.17.0, ...
Read more >
Fetching and Using Blob Data in React Native: Demystified
In this post, we'll explore how to fetch and handle blob data in React Native applications properly.
Read more >
Issues · RonRadtke/react-native-blob-util - GitHub
A project committed to making file access and data transfer easier, efficient for React Native developers.
Read more >
Does react native support Blob? - Stack Overflow
Okay i have perform those steps and converted the base64 data into blob. In order to make a service call, my cloud services...
Read more >
Blob support | Voters - Expo - Canny
Seems like React Native Blob support is very basic and not really offering the same capability as react-native-fetch-blob does. For example I cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found