Back

Server Error when uploading base64 encoded file to storage.createFile() with server-sdk

  • 0
  • Self Hosted
  • Storage
shekpaar
11 Oct, 2024, 02:39

I have a nextjs application, where I want to upload files to appwrite storage. Files are base64 encoded.

I am using: Server sdk: "node-appwrite": "^14.1.0", Appwrite 1.6.0

TypeScript
import {Client, Databases, ID, Storage} from 'node-appwrite';
import {InputFile} from 'node-appwrite/file';

const buffer = Buffer.from(base64Data, 'base64');
                    try {
                        await storage.createFile(
                            process.env.APPWRITE_BUCKET_ID as string,
                            ID.unique(),
                            InputFile.fromBuffer(buffer, name),
                        );
                    } catch (err) {
                        console.error('Error:', err);
                    }

Thats the begin of the base64 string:

TypeScript
base64: 'iVBORw0KGgoAAAANSUhEUgAAB9AAAAfQCAYAAACaOMR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAuhZJREFUeNrswQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAA

The error is:

TypeScript
Error: AppwriteException: Server Error
    at _Client.call (webpack-internal:///(rsc)/./node_modules/node-appwrite/dist/client.mjs:285:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async _Client.chunkedUpload (webpack-internal:///(rsc)/./node_modules/node-appwrite/dist/client.mjs:221:20)
    at async Storage.createFile (webpack-internal:///(rsc)/./node_modules/node-appwrite/dist/services/storage.mjs:268:16)
    at async eval (webpack-internal:///(rsc)/./app/api/data/route.ts:193:25) {
  code: 500,
  type: 'general_unknown',
  response: {
    message: 'Server Error',
    code: 500,
    type: 'general_unknown',
    version: '1.6.0'
  }
}
TL;DR
Developers experiencing a server error when trying to upload a base64 encoded file to Appwrite storage using server-sdk. The error message indicates a 500 Server Error. Possible issue with how the file is being processed before upload. Verify encoding and the file itself.
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