
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
- Google login error: {"message":"Invalid ...
hi, im trying to use google login with account.createOAuth2Session( 'google', 'profevardilla.pages.dev', 'profevardilla.pages.dev'...
- Upload file
i got this error when try upload file (.Net). I use this line to check my buucket and its all right var buckets = await appWriterInit.Storage.List...
- Auth Error
"use client"; import { useEffect } from "react"; import { getSessionCookie } from "@/actions/auth"; import { createBrowserSessionClient } from "@/lib/appwrite-...
