
hi, i want to upload a image to a appwrite bucket, also i am using sveltekit. For some reason i get the error source.on is not a function, can someone tell me what i did wrong here because i feel like it is something dumb. how it works: user on the client uploads a image via form, form data gets sent to the backend, the image is processed on a backend and image should be sent to the bucket via backend
my code: frontend: +page.svelte
<script lang="ts">
import Input from '$lib/components/Input.svelte';
import Button from '$lib/components/Button.svelte';
import { enhance } from '$app/forms';
</script>
<div class="post-wrapper">
<h1>post joke</h1>
<form action="?/post" method="POST" enctype="multipart/form-data" use:enhance>
<Input name="title" type="text" placeholder="title" />
<Input type="file" accept="image/*" name="image" />
<Button>post joke</Button>
</form>
</div>
backend: +page.server.ts
import { ID, Databases, Client, Storage } from 'appwrite';
import { Buffer } from 'buffer';
import { InputFile } from 'node-appwrite/file';
export const actions = {
post: async ({ request }) => {
const data = await request.formData();
const image = data.get('image');
const arrayBuffer = await image.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1') // API Endpoint
.setProject('xxx'); // project ID
const storage = new Storage(client);
const result = await storage.createFile(
'xxx', // bucketId
ID.unique(),
InputFile.fromBuffer(buffer, 'sssss')
);
console.log(result);
}
};
i read the docs it says that i should use the InputFile when the image is processed on a backend, i made the bucket any with everything checked
thanks in advance.
Recommended threads
- Appwrite Fra Cloud Custom Domains Issue
I’m trying to configure my custom domain appwrite.qnarweb.com (CNAME pointing to fra.cloud.appwrite.io with Cloudflare proxy disabled) but encountering a TLS ce...
- Appwrite service :: getCurrentUser :: Us...
Getting this error while creating a react app can someone please help me solve the error
- Storage & Database is not allowing.
Storage & Database is not allowing to CRUD after i have logged in ? Using web SDK with next.js without any SSR or node-sdk.
