Javascript React native无法将图像上载到firebase
我正在尝试将图像上载到firebase存储或firestore,但出现以下错误: {“代码”:“存储/无效参数”,“消息”:“Firebase存储:索引0处的Javascript React native无法将图像上载到firebase,javascript,firebase,react-native,google-cloud-firestore,google-cloud-storage,Javascript,Firebase,React Native,Google Cloud Firestore,Google Cloud Storage,我正在尝试将图像上载到firebase存储或firestore,但出现以下错误: {“代码”:“存储/无效参数”,“消息”:“Firebase存储:索引0处的put中的无效参数:应为Blob或文件。”,“名称”:“FirebaseError”,“serverResponse”:null} 我如何解决这个问题 我知道我必须将图像转换为文件或blob格式 但在这种情况下,我该怎么做 附言:我不是在用世博会 下面是我拍摄图像的函数 const handleSelectPicture = useCall
put
中的无效参数:应为Blob或文件。”,“名称”:“FirebaseError”,“serverResponse”:null}
我如何解决这个问题
我知道我必须将图像转换为文件或blob格式
但在这种情况下,我该怎么做
附言:我不是在用世博会
下面是我拍摄图像的函数
const handleSelectPicture = useCallback(() => {
ImagePicker.showImagePicker(
{
noData: true,
title: 'Selecione a foto desejada',
cancelButtonTitle: 'Cancelar',
takePhotoButtonTitle: 'Usar câmera',
maxWidth: 800,
maxHeight: 800,
chooseFromLibraryButtonTitle: 'Escolher da galeria',
},
response => {
if (response.didCancel) {
return;
}
if (response.error) {
Alert.alert('Erro ao fazer upload da foto, tente novamente.');
return;
}
console.log('image: >>>> ', response.uri);
setImageURI({ uri: response.uri });
console.log('State uri>>>>', imageURI);
},
);
}, [imageURI]);
下面是我如何尝试将该图像上载到firebase:
错误消息:
索引0处的put中的参数无效:应为Blob或文件
正在告诉您向传递了无效值。如果您希望将URL传递到其他文件以进行上载,那么这是行不通的。您只能上载运行代码的计算机上本地存在的内容
如果您想传输另一个URL的内容,则无法使用web客户端SDK进行传输。您必须编写一些后端代码从URL下载内容,然后将其上载到云存储。错误消息:
索引0处的put中的参数无效:应为Blob或文件
正在告诉您向传递了无效值。如果您希望将URL传递到其他文件以进行上载,那么这是行不通的。您只能上载运行代码的计算机上本地存在的内容
如果您想传输另一个URL的内容,则无法使用web客户端SDK进行传输。您必须编写一些后端代码从URL下载内容,然后将其上载到云存储。我试图上载一个仅存在于我的模拟器中的图像,这不起作用??您必须找到一种方法,以API接受的方式引用该图像。我试图上载一个仅存在于我的模拟器中的图像,无法工作??您必须找到一种方法,以API接受的方式引用该图像。
await firebase
.auth()
.createUserWithEmailAndPassword(
email,
password,
)
.then(async auth => {
console.log('valueee', auth);
await db
.collection('users')
.doc('userData')
.set({
photo: imageURI,
document: params.fileSelected,
address: [data],
});
firebase
.storage()
.ref(`users/${auth.user.uid}/profileImage.jpg`)
.put(imageURI.uri)
.then(() => {
setUser(auth);
});
})