Back

How to upload a File object using the NodeJS SDK ? (Not Blob, Buffer...)

  • 0
  • Storage
Alex
7 Feb, 2024, 15:46

The docs point towards using one of the sdk methods InputFile.fromPath(), InputFile.fromBuffer() etc... in case you're on the server side.

But I want to upload directly a File object, I tried this but obviously it's not working because File is not an assignable parameter given the InputFile method.

TypeScript
const FILE = formData.get('dataModel');
if (FILE instanceof File) {
    const promise = storage.createFile(BUCKET_ID, FILE_ID, FILE);

The file I am dealing with is a File object likes this one:

TypeScript
File {
  size: 75621,
  type: 'application/json',
  name: 'xquad-ca_predictions.json',
  lastModified: 1707319609241
}

Docs source: https://appwrite.io/docs/products/storage/upload-download#server-sdks

TL;DR
Developers are trying to upload a File object using the NodeJS SDK in Appwrite. The documentation suggests using methods like `InputFile.fromPath()` or `InputFile.fromBuffer()`, but the developer wants to upload the File object directly. They tried passing the File object to the `createFile` method, but it didn't work because the File object is not an assignable parameter for the InputFile method. Solution: Unfortunately, the NodeJS SDK does not currently support uploading File objects directly. You will need to convert the File object into a Blob or Buffer before uploading it using the SDK methods mentioned in the documentation.
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