
hi, today i started using the appwrite, it is super simple but one think that got me stuck for the past 3 hours is not being able to uplad a image to a bucket, here is my code and i would explain what i want to acheve:
+PAGE.SVELTE CODE
<form use:enhance action="?/postskin" method="POST" enctype="multipart/form-data">
<input type="text" placeholder="naslov" name="title" />
<input type="file" name="image" accept="image/*" required />
<button><Plus /> POST SKIN</button>
</form>
+PAGE.SERVER.JS CODE
import { Client, ID, Storage } from 'appwrite';
export const actions = {
postskin: async ({ request }) => {
const data = await request.formData();
const image = data.get('image');
console.log(image);
console.log(image.type);
const client = new Client().setEndpoint('https://cloud.appwrite.io/v1').setProject('xxxxxxxxx');
const storage = new Storage(client);
try {
const result = await storage.createFile('xxxxxxxx', ID.unique(), image);
console.log(result);
return { success: 'Image uploaded successfully' };
} catch (error) {
console.error('Error uploading file:', error);
return { error: 'Failed to upload image' };
}
}
};
so i want my image to get upladed to bucket what i did: made sure that my id-s are correct, setuped the permisions to any with everything checked
what i get:
File {
size: 2138,
type: 'image/png',
name: 's.png',
lastModified: 1743171671561
}
image/png
Error uploading file: TypeError: source.on is not a function
if someone can explain to me what i did wrong or what should i do it would be highly apreciated
sorry for bad english
Recommended threads
- Stuck in "deleting"
my parent element have relationship that doesnt exist and its stuck in "deleting", i cant delete it gives me error: Collection with the requested ID could not b...
- Help with 409 Error on Relationship Setu...
I ran into a 409 document_already_exists issue. with AppWrite so I tried to debug. Here's what I've set up: Collection A has 3 attributes and a two-way 1-to-m...
- Database Double Requesting Error.
I am getting error for creating new document in an collection with new ID.unique() then too getting error of existing document. When button is pressed one docum...
