Hello, I have encountered some issue with uploading an image to the bucket.
Usually, image upload is done from local point, however on some tutorial that was done recently, image url does point to the remote url, instead of local path to the image, and it does work there.
async function uploadImageToStorage(imageUrl: string) {
try {
const response = await fetch(imageUrl);
const blob = await response.blob();
const fileObj = {
name: imageUrl.split("/").pop() || `file-${Date.now()}.jpg`,
type: blob.type,
size: blob.size,
uri: imageUrl,
};
const file = await storage.createFile({
bucketId: appwriteConfig.bucketId,
fileId: ID.unique(),
file: fileObj,
});
return storage.getFileViewURL(appwriteConfig.bucketId, file.$id);
} catch (error) {
console.log("Returned an error:", error);
}
}
Here is sample data (sorry if included image url). So it does not pass the point to create a file, as uri is remote.
{
name: "Classic Cheeseburger",
description: "Beef patty, cheese, lettuce, tomato",
image_url:
"https://static.vecteezy.com/system/resources/previews/044/844/600/large_2x/homemade-fresh-tasty-burger-with-meat-and-cheese-classic-cheese-burger-and-vegetable-ai-generated-free-png.png",
price: 25.99,
rating: 4.5,
calories: 550,
protein: 25,
category_name: "Burgers",
customizations: ["Extra Cheese", "Coke", "Fries", "Onions", "Bacon"],
},
for (const item of data.menu) {
const uploadedImage = await uploadImageToStorage(item.image_url);
Is there any flag/permission that I can add to obj that allows pull from remote url, so I don't need to use local images?
Recommended threads
- Upgrading selfhost version?
It is okay to upgrade version to higher one, of my current version is 1.7.4 to 1.8.1. Is that safe to do cause my clients already have data on that? Also is a...
- I am using s3 for app storage but is it ...
_APP_STORAGE_DEVICE=s3 puts everything to the s3 storage but i need to be able to keep the function builds and site in the local and not waste the cloud storage...
- Appwrite cloud DB server error 500
Getting this error