Back

Can I use the appwrite SDKs storage methods on +page.server.ts function on Sveltekit ?

  • 0
  • Web
  • Storage
Alex
19 Feb, 2024, 11:28

Trying to create and send a file to the storage files but receiving an error

TypeScript
import * as sdk from 'node-appwrite';
export const actions = {
    default: async ( {request} ) => {
       const formData = await request.formData();
       const data = formData.get('dataModel');
       const blob = new Blob([data], { type: file.type});
       const promise = storage.createFile(
          BUCKET_ID, 
          sdk.ID.unique(), 
          sdk.InputFile.fromBlob(blob, file.name)
        );
    }
}

Error:

TypeScript
TypeError: Cannot read properties of undefined (reading 'pipe')
TL;DR
Developers are encountering errors when attempting to use the appwrite SDKs storage methods inside a Sveltekit server-side function. The issue seems to stem from the 'request' object not including the necessary methods for file handling. To resolve this problem, developers can try passing along the file directly to the storage createFile method, rather than using formData.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more