Skip to content

Instantly share code, notes, and snippets.

@louicoder
Created March 22, 2020 10:50
Show Gist options
  • Save louicoder/35291a173c137ba779fe94c2d5aa8746 to your computer and use it in GitHub Desktop.
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
// 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