如何解决我如何使用 Firestore 将我的文件放在我的存储中?
我想我忘记了一个步骤,因为当我尝试将图片上传到 firebase 存储时,我可以在 console.log 上看到路径,但是当我使用 putfile 上传时,出现此错误:
错误:[storage/file-not-found] 指定的本地文件在设备上不存在。 NativeFirebaseError: [storage/file-not-found] 指定的本地文件在设备上不存在。
也是我的功能:
unction GetPictures() {
const reference = storage().ref("PicturesUsers/Avatar.png");
const [response,setResponse] = React.useState();
return (
<SafeAreaView>
{response && (
<View style={styles.image}>
<Image
style={{ width: 200,height: 200,borderRadius: 200 }}
source={{ uri: response.uri }}
/>
</View>
)}
<View style={{ marginTop: -70 }}>
<Icon
name="camera-retro"
size={30}
color="#5DC1D3"
onPress={async () =>
launchImageLibrary(
{
mediaType: "photo",includeBase64: false,maxHeight: 200,maxWidth: 200,},async (response) => {
let reference = storage().ref("PicturesUsers/avatar.png");
let image = response;
const pathToFile =
`${utils.FilePath.PICTURES_DIRECTORY}/` + response.uri;
await reference.putString(pathToFile);
await reference.putFile(pathToFile);
console.log(pathToFile);
},async (response) => {
firestore()
.collection("Users")
.doc(await AsyncStorage.getItem("userID"))
.update({
Picture: response,})
.then(async () => {
setResponse(response);
console.log(pathToFile);
firestore()
.collection("Users")
.doc(await AsyncStorage.getItem("userID"))
.get()
.then((documentSnapshot) => {
console.log("User exists: ",documentSnapshot.exists);
if (documentSnapshot.exists) {
console.log(
"User data: ",documentSnapshot.data().Picture.uri
);
}
});
});
}
)
}
/>
</View>
</SafeAreaView>
);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。