Created
December 1, 2017 11:49
-
-
Save gHashTag/b0fae0a5fcad70142540be3a59cb2dbe to your computer and use it in GitHub Desktop.
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
| 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