我目前可以通过将图像存储在Blob中并将其上传到Firestore来将其上传到Firebase Firestore。除了影片,我该怎么做?我也将它放在Blob中吗?下面是我用来上传图片的代码。
openLibrary = async () => {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL)
if (status === 'granted') {
const image = await ImagePicker.launchImageLibraryAsync({allowsEditing: true})
if(!image.cancelled){
const url = await this.props.uploadPhoto(image)
this.props.updatePhoto(url)
}
}
}
export const uploadPhoto = (image) => {
return async (dispatch) => {
try {
console.log("in upload photo")
const resize = await ImageManipulator.manipulateAsync(image.uri, [], { format: 'jpeg', compress: 0.1 })
const blob = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.onload = () => resolve(xhr.response)
xhr.responseType = 'blob'
xhr.open('GET', resize.uri, true)
xhr.send(null)
});
const uploadTask = await firebase.storage().ref().child(uuid.v4()).put(blob)
const downloadURL = await uploadTask.ref.getDownloadURL()
return downloadURL
} catch(e) {
console.log("in upload photo error")
console.error(e)
}
}
}