React Native:使用哪个 firebase 存储 npm 包?
React Native: which firebase storage npm package to use?
React native 和 Firebase 的学习者。
这是我初始化 firebase 存储和获取 url 存储路径的代码:
import { firebase } from '@react-native-firebase/storage';
var firebaseConfig = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const storage = firebase.storage();
let imageRef = firebase.storage().ref('photos/flower.png');
console.log(imageRef);
我希望 imageRef
包含 url 用于 Firebase 存储的图像文件。
但我收到错误消息:
ERROR TypeError: undefined is not an object (evaluating
'_firebase.firebase.storage')
感觉是包名导入错误
有人可以指导我哪里出了问题吗?
I expect imageRef to be containing url for the Firebase storage's image file.
首先,您应该遵循文档中的example。
Unlike the Firebase Web SDK, there is no need to manually call the initializeApp method with your project credentials.
因此,如果设置正确,则根本不必调用 initializeApp。
ref() returns a Reference type object, which is just a pointer to the file. If you want an HTTPS type URL to download the content of that file, you will need to use its getDownloadURL 获取方法。
import storage from '@react-native-firebase/storage';
let imageRef = storage().ref('photos/flower.png');
imageRef.getDownloadURL().then(url => {
console.log(url);
})
React native 和 Firebase 的学习者。
这是我初始化 firebase 存储和获取 url 存储路径的代码:
import { firebase } from '@react-native-firebase/storage';
var firebaseConfig = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const storage = firebase.storage();
let imageRef = firebase.storage().ref('photos/flower.png');
console.log(imageRef);
我希望 imageRef
包含 url 用于 Firebase 存储的图像文件。
但我收到错误消息:
ERROR TypeError: undefined is not an object (evaluating '_firebase.firebase.storage')
感觉是包名导入错误
有人可以指导我哪里出了问题吗?
I expect imageRef to be containing url for the Firebase storage's image file.
首先,您应该遵循文档中的example。
Unlike the Firebase Web SDK, there is no need to manually call the initializeApp method with your project credentials.
因此,如果设置正确,则根本不必调用 initializeApp。
ref() returns a Reference type object, which is just a pointer to the file. If you want an HTTPS type URL to download the content of that file, you will need to use its getDownloadURL 获取方法。
import storage from '@react-native-firebase/storage';
let imageRef = storage().ref('photos/flower.png');
imageRef.getDownloadURL().then(url => {
console.log(url);
})