
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
- Cant retrieve data
i cant retrieve my data
- Queries Length Error.
Hi All, I am having a issues across my app with how i am getting data, and just wanted to check if this was an issues with the new changes on appwrite over the...
- Explore uploaded images directly from lo...
Is there any option to explore/dwonload uploaded files to from local machine? I connected through WinScp to my vps and to files from docker volume 'appwrite_app...
