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.

react native download as blob unsupported

See original GitHub issue

Looks like there’s an error when calling filesDownload in a react native app. Output error:

{ [Invariant Violation: The provided value 'blob' is unsupported in this environment.] line: 2074, column: 16, sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false', name: 'Invariant Violation', framesToPop: 1 }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rubengarciamcommented, Jan 1, 2017

@RileyTomasek @evanbattaglia Couldn’t make it work for large files or some formats. Managed to get it working using react-native-fs’ downloadFile and calling Dropbox’s download HTTP endpoint instead

RNFS.downloadFile({ fromUrl: "https://content.dropboxapi.com/2/files/download", toFile: localPath, headers: {"Authorization": "Bearer XXXXXX", "Dropbox-API-Arg": JSON.stringify({path: PATH})} }).promise.then((response) => { if (response.statusCode == 200) { console.log('FILES Downloaded!') } else { console.log('SERVER ERROR') }})

0reactions
evanbattagliacommented, Jan 6, 2017

Indeed, https://github.com/evanbattaglia/dropbox-sdk-js/commit/fbb202abbcf9e1a359293892863e8e155b471c90 seems to work for me.

_Edit_: I’ve discovered that a better way to get binary data for React Native is with ArrayBuffers (e.g. this.xhr.responseType = 'arraybuffer'):

https://github.com/dropbox/dropbox-sdk-js/compare/master...evanbattaglia:evanbattaglia/download-react-native?expand=1

With this ArrayBuffer to base64 gist (https://gist.github.com/jonleighton/958841) you can then write the file out with react-native-fs, with e.g.:

RNFS.writeFile(dest, base64ArrayBuffer(resp.fileArrayBuffer), 'base64');

Kind of awkward but the best I’ve found so far.

Edit: See rubengarciam’s solution below, it works for me and is simpler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unsupported URL #352 - wkh237/react-native-fetch-blob
I'm using this package as a replacement for JS Fetch. I have calls to different URLs. all works fine except one :.
Read more >
Format error when downloading Blob from React
I'm trying to download a Blob from React that can be either a PDF or an image(jpg, jpeg, png...). PDF's are downloading good...
Read more >
How to Download an Image in React Native from any URL
To download an image using rn-fetch-blob we will use the RNFetchBlob component which provides a fetch method with some different configuration. Here is...
Read more >
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 >
Download Files in React Native with RNFetchBlob
Download Files in React Native with RNFetchBlob. A concise and easy-to-follow guide on downloading files in React Native apps.
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