HOC react redux firebase. (Error: Firebase storage is required to upload files)
HOC react redux firebase. (Error: Firebase storage is required to upload files)
需要 Firebase 存储错误
可能是我向 uploadFile() 提供参数有误。
如果您看到任何内容,请提出更正建议
代码:
export const addCategory = category => {
return (dispatch, getState, { getFirestore, getFirebase }) => {
const firebase = getFirebase();
const firestore = getFirestore();
let reader = new FileReader();
reader.readAsDataURL(category.imageFile);
const imageExtension = category.imageFile.name.split('.')[
category.imageFile.name.split('.').length - 1
];
var imageFileName = `${Math.round(
Math.random() * 100000000000
)}.${imageExtension}`;
reader.onload = e => {
const storagePath = "https://firebasestorage.googleapis.com/v0/b/grocapp-f4eb9.appspot.com/o/";
const dbPath = 'test';
const fileMetadata = { contentType: 'image/jpeg' };
firebase
.uploadFile(storagePath, e.target.result, dbPath, { metadata: fileMetadata })
.then(() => {
console.log('File uploaded successfully');
});
};
};
};
浏览器中的错误代码:
Error: Firebase storage is required to upload files
19 | const dbPath = 'test';
20 | const fileMetadata = { contentType: 'image/jpeg' };
21 |
> 22 | firebase
23 |^ .uploadFile(storagePath, e.target.result, dbPath, { metadata: fileMetadata })
24 | .then(() => {
25 | console.log('File uploaded successfully');
我认为你应该安装 @firebase/storage
如果你还没有安装并导入它
It is checked in the start of uploadFile method
import "firebase/storage";
需要 Firebase 存储错误 可能是我向 uploadFile() 提供参数有误。 如果您看到任何内容,请提出更正建议 代码:
export const addCategory = category => {
return (dispatch, getState, { getFirestore, getFirebase }) => {
const firebase = getFirebase();
const firestore = getFirestore();
let reader = new FileReader();
reader.readAsDataURL(category.imageFile);
const imageExtension = category.imageFile.name.split('.')[
category.imageFile.name.split('.').length - 1
];
var imageFileName = `${Math.round(
Math.random() * 100000000000
)}.${imageExtension}`;
reader.onload = e => {
const storagePath = "https://firebasestorage.googleapis.com/v0/b/grocapp-f4eb9.appspot.com/o/";
const dbPath = 'test';
const fileMetadata = { contentType: 'image/jpeg' };
firebase
.uploadFile(storagePath, e.target.result, dbPath, { metadata: fileMetadata })
.then(() => {
console.log('File uploaded successfully');
});
};
};
};
浏览器中的错误代码:
Error: Firebase storage is required to upload files
19 | const dbPath = 'test';
20 | const fileMetadata = { contentType: 'image/jpeg' };
21 |
> 22 | firebase
23 |^ .uploadFile(storagePath, e.target.result, dbPath, { metadata: fileMetadata })
24 | .then(() => {
25 | console.log('File uploaded successfully');
我认为你应该安装 @firebase/storage
如果你还没有安装并导入它
It is checked in the start of uploadFile method
import "firebase/storage";