我正在使用 supabase auth、数据库和表格创建一篇博客文章,博主可以在其中发布博客。
此帖子包含帖子详细信息和最多 4 张图片。
如何使用 uppy 将可断点续传的图像详细信息上传到帖子表,同时在博主上传后保存图像的网址?
我能够将图像上传到supabase存储,并且我为图像url创建了数组属性,我还设置了一个触发器来调用一个函数,该函数在上传后更新博客表的详细信息,但这仍然会遇到错误
经过对 uppy 的更多研究,我设法解决了这个问题。
try {
uppy.upload().then(async (result) => {
const description = blogDescriptionRef.current.value;
const title = blogTitleRef.current.value;
if (result.failed.length > 0) {
toast.error("Image upload failed");
} else {
const imageUrls = result.successful.map((file) => file.uploadURL);
const {
data: { user },
} = await supabase.auth.getUser();
if (description.trim() && title.trim()) {
const { error } = await supabase
.from("posts")
.insert({
name: title,
product_images: imageUrls,
title: description,
});
if (error) throw error;
}
}
});
} catch (error) {
toast.error("Error saving blog:");
}