如何将图像列表上传到firebase存储并获取所有url



我使用firebase存储上传图像,然后将url存储到firebase db。我用它来上传图像列表,但下面的代码在firebase v8中工作良好,但在版本9中不行

export const multiImageUpload = async (path = "Products", imageFileList) => {
let imagesUrlArray = [];
let imageUrl = "";
// array of files
let arr = imageFileList.map((item) => {
return item.originFileObj;
});
for (let i = 0; i < arr.length; i++) {
const upload = await storage.ref(`/${path}/${arr[i].name}`).put(arr[i]);
imageUrl = await upload.ref.getDownloadURL();
imagesUrlArray.push(imageUrl);
}
return imagesUrlArray; // array of URLS of uploaded files
};

抛出ref.put不是函数的错误请告诉我为什么我得到这个错误。

import {ref, getDownloadURL, uploadBytesResumable, uploadBytes} from 'firebase/storage';

// Upload the multiple images
const multiImage = async (imageFileList) => {
/* eslint no-var: 0 */
const imagesUrlArray = [];
/* eslint no-var: 0 */
for (let i = 0; i < imageFileList.length; i++) {
const id = uuidv4();
const metadata = {
contentType: 'image/jpeg'
};
/* eslint-disable no-await-in-loop */
const storageRef = ref(storage, `images/${id}`);
const upload = await uploadBytes(storageRef, imageFileList[i], metadata);
const imageUrl = await getDownloadURL(storageRef);
imagesUrlArray.push(imageUrl);
}
return imagesUrlArray; // array of URLS of uploaded files
};

相关内容

  • 没有找到相关文章

最新更新