Skip to content

Instantly share code, notes, and snippets.

@gHashTag
Created December 1, 2017 11:49
Show Gist options
  • Select an option

  • Save gHashTag/b0fae0a5fcad70142540be3a59cb2dbe to your computer and use it in GitHub Desktop.

Select an option

Save gHashTag/b0fae0a5fcad70142540be3a59cb2dbe to your computer and use it in GitHub Desktop.
import { Platform } from 'react-native'
import RNFetchBlob from 'react-native-fetch-blob'
const Blob = RNFetchBlob.polyfill.Blob
const fs = RNFetchBlob.fs
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
window.Blob = Blob
// User-related helper functions
export const uploadImage = (imageUri, uid, mime = 'application/octet-stream') => {
console.log('imageUri', imageUri)
return new Promise((resolve, reject) => {
const uploadUri = Platform.OS === 'ios' ? imageUri.replace('file://', '') : imageUri
console.log('uploadUri', uploadUri)
let uploadBlob = null
//const storageRef = firebase.storage().ref()
//const databaseRef = firebase.database().ref(`users/${uid}`)
//const imageStorageRef = storageRef.child(`profilePhotos/${uid}/profilePhoto.jpg`)
fs.readFile(uploadUri, 'base64')
.then((data) => {
return Blob.build(data, { type: `${mime}BASE64` })
})
.then((blob) => {
//uploadBlob = blob
//return imageStorageRef.put(blob, { contentType: mime })
})
.then(async () => {
//uploadBlob.close()
//let downloadUrl = await imageStorageRef.getDownloadURL()
//databaseRef.update({
//profilePhotoUrl: downloadUrl
//})
//return downloadUrl
})
.then((url) => {
resolve(url)
})
.catch((error) => {
reject(error)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment