#[SOLVED] InputFile replaced by File in server SDK, breaking compatibility with Node.js 18 and lower

14 messages ยท Page 1 of 1 (latest)

leaden solstice
#

Hello everyone! ๐Ÿ‘‹๐Ÿป

Recently I upgraded my cloud function from version 12.0.1 to the latest version, version 14.2.0. InputFile was removed and replaced by File. This caused some problems. Below I share the solution:

In my cloud function I have a function:

await storage.createFile(photoBucketId, 'unique()', new InputFile(Readable.from(buffer), "photo.jpg", Buffer.byteLength(buffer)));

A breaking change in at least version 14.2.0 is the removal of InputFile. It is replaced by File. This is what the new function call look likes after removing InputFile.

await storage.createFile(photoBucketId, 'unique()', new File([buffer], "photo.jpg");

File isn't supported by Node.js lower than version 22. It results in a ReferenceError: File is not defined error. If you want to stay on version 18 then you can use the web-file-polyfill package:

https://www.npmjs.com/package/web-file-polyfill

Just add it to your package.json, import it and you're done: import { File, Blob } from "web-file-polyfill. I tested this on Appwrite Cloud and it works as expected, as far as I can tell.

flat dew
leaden solstice
#

Anything below Node.js 22 doesn't support File, unless that web-file-polyfill package is used as a workaround.

flat dew
leaden solstice
#

Yes, that's what I tried. But createFile in 14.2.0 in doesn't take an InputFile. It takes a File object.

flat dew
leaden solstice
leaden solstice
flat dew
leaden solstice
#

I'm going to look into this and see if I can get it to work by using static methods. ๐Ÿ˜Š

leaden solstice