Created
March 22, 2020 10:50
-
-
Save louicoder/35291a173c137ba779fe94c2d5aa8746 to your computer and use it in GitHub Desktop.
Creating a blob file to upload to firebase storage bucket when using react-native-image-picker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uri is the uri property on the response object from reactnative image picker | |
function convertUriToBlobFile = (uri) => { | |
return new Promise((resolve, reject) => { | |
const xhr = new XMLHttpRequest(); | |
xhr.onload = function () { | |
// return the blob | |
resolve(xhr.response); | |
// setBlob(xhr.response); | |
}; | |
xhr.onerror = function () { | |
// something went wrong | |
reject(new Error('uriToBlob failed')); | |
}; | |
// this helps us get a blob | |
xhr.responseType = 'blob'; | |
xhr.open('GET', uri, true); | |
// send back blob file created from uri | |
xhr.send(null); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment