Closed simseb closed 1 month ago
Cheers @simseb . I've been struggling with this error for a while.
Typescript even tells us that InputFile.fromBuffer
doesn't accept bufferFile
type... but the fact is, this code works so thank you very much. I'll use this as a temporary solution.
Here's my code in case someone wants to add a little more type-check and silence their typescript.
node -> v18.19.1 node-appwrite -> ^13.0.0
// helper function in lib/utils.ts
export function isBlob(value: unknown): value is Blob {
return value instanceof Blob;
}
if (identificationDocument) {
// Get the Blob object from the identificationDocument
const blob = identificationDocument?.get('blobFile');
// Make sure we have a blob type of file in identificationDocument
if (!blob || !isBlob(blob)) throw new Error('Blob file was not found');
// !! Transform blob into buffer so we can use it and fix "TypeError [ERR_INVALID_STATE]" error
// !! See solution here: https://github.com/adrianhajdin/healthcare/issues/32
const bufferFile = await blob.arrayBuffer();
const inputFile = InputFile.fromBuffer(
// @ts-ignore
bufferFile, // !! Typescript is correct in complaining. However at the moment Blob does not work so for now we keep it like this
identificationDocument?.get('fileName') as string,
);
}
Node version: v18.19.1 "node-appwrite": "^13.0.0"
File upload fixed with these relevant lines: