Reputation: 1
I'm creating a blog post with supabase auth, database and tables, where a blogger can post a blog.
This post contains the post details and upto 4 images.
How can I upload this details using uppy for images with resumable download, to the post table and at the same time save the urls of the images after the blogger uploads?
I'm able to upload the images to supabase storage, and i created and array attribute for image urls, i also set a trigger to call a function that updates the blog table after the upload with the details, but this still runs into an error
Upvotes: 0
Views: 262
Reputation: 1
After more research on uppy, i manages to solve this issue.
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:");
}
Upvotes: 0