如何在React Native中将视频上传到firebase firestore

问题描述 投票:0回答:1

我目前可以通过将图像存储在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)
    }
  }
}
javascript firebase react-native google-cloud-firestore firebase-storage
1个回答
0
投票

您如何尝试下载文件?

也许当您上传视频时,您没有在上传或下载(mp4,mov等)时设置文件类型/扩展名。

尝试添加所需的文件扩展名,请参阅this link

© www.soinside.com 2019 - 2024. All rights reserved.