adrianhajdin / healthcare

Build a healthcare platform that streamlines patient registration, appointment scheduling, and medical records, and learn to implement complex forms and SMS notifications.
https://jsmastery.pro
1.81k stars 432 forks source link

TypeError: Module '"node-appwrite"' has no exported member 'InputFile' #16

Open Vicidevs opened 2 months ago

Vicidevs commented 2 months ago

Cannot find the InputFile, any alternative?

paull-30 commented 2 months ago

use import { InputFile } from 'node-appwrite/file';

bharatpaliwal-169 commented 2 months ago

use import { InputFile } from 'node-appwrite/file';

and use InputFile.fromBuffer().

biyiemmy commented 2 months ago

use import { InputFile } from 'node-appwrite/file';

this seems not to be working from my end

KelberStuchi commented 1 month ago

// patient.actions.ts

"use server";

import { ID, Query } from "node-appwrite"; import { InputFile } from "node-appwrite/file";

import { BUCKET_ID, DATABASE_ID, ENDPOINT, PATIENT_COLLECTION_ID, PROJECT_ID, databases, storage, users, } from "../appwrite.config"; import { parseStringify } from "../utils";

// CREATE APPWRITE USER export const createUser = async (user: CreateUserParams) => { try { // Create new user -> https://appwrite.io/docs/references/1.5.x/server-nodejs/users#create const newuser = await users.create( ID.unique(), user.email, user.phone, undefined, user.name );

return parseStringify(newuser);

} catch (error: any) { // Check existing user if (error && error?.code === 409) { const existingUser = await users.list([ Query.equal("email", [user.email]), ]);

  return existingUser.users[0];
}
console.error("An error occurred while creating a new user:", error);

} };

// GET USER export const getUser = async (userId: string) => { try { const user = await users.get(userId);

return parseStringify(user);

} catch (error) { console.error( "An error occurred while retrieving the user details:", error ); } };

// REGISTER PATIENT export const registerPatient = async ({ identificationDocument, ...patient }: RegisterUserParams) => { console.log("identificationDocument", identificationDocument); console.log("patient", patient);

try { // Upload file -> // https://appwrite.io/docs/references/cloud/client-web/storage#createFile let file; if (identificationDocument) { const inputFile = identificationDocument && InputFile.fromBuffer( identificationDocument?.get("blobFile") as Blob, identificationDocument?.get("fileName") as string );

  file = await storage.createFile(BUCKET_ID!, ID.unique(), inputFile);
}
// Create new patient document -> https://appwrite.io/docs/references/cloud/server-nodejs/databases#createDocument
const newPatient = await databases.createDocument(
  DATABASE_ID!,
  PATIENT_COLLECTION_ID!,
  ID.unique(),
  {
    identificationDocumentId: file?.$id ? file.$id : null,
    identificationDocumentUrl: file?.$id
      ? `${ENDPOINT}/storage/buckets/${BUCKET_ID}/files/${file.$id}/view??project=${PROJECT_ID}`
      : null,
    ...patient,
  }
);
console.log("new Patient", newPatient);

return parseStringify(newPatient);

} catch (error) { console.error("An error occurred while creating a new patient:", error); } };

biyiemmy commented 1 month ago

import { InputFile } from 'node-appwrite/file';

let file; if (identificationDocument) { const inputFile = identificationDocument && InputFile.fromBuffer( identificationDocument?.get("blobFile") as Blob, identificationDocument?.get("fileName") as string ); file = await storage.createFile(BUCKET_ID!, ID.unique(), inputFile); }

Hi bro can you share the full code, it seems Im not getting you

TkRj commented 1 month ago

I encountered an import error for 'fs' module for the InputFile module. This is due to fs not being available in the browser as it only exists in nodejs environment. If you face the same issue, go to next.config.mjs file and update with the following:

Code const nextConfig = { future: { webpack5: true, }, webpack(config) { config.resolve.fallback = { ...config.resolve.fallback, fs: false, }; return config; }, };`

source

alfattal7 commented 1 month ago

use this const sdk = require('node-appwrite'); and befor any function of "node-appwrite" just right sdk => sdk.Query.equal("email", [user.email]) etc.

FinzyPHINZY commented 1 month ago

I encountered an import error for 'fs' module for the InputFile module. This is due to fs not being available in the browser as it only exists in nodejs environment. If you face the same issue, go to next.config.mjs file and update with the following:

Code source

This works!

KevinFalah commented 1 month ago

use import { InputFile } from 'node-appwrite/file';

its worked for me, thanks

SanadKhan commented 1 month ago

@biyiemmy @Vicidevs

node-appwrite13.0.0

in your utils file add

export const getBufferImage = async(fileInfo: File) => {
  try {
    const bytes = await fileInfo.arrayBuffer();
    const bufferImage = Buffer.from(bytes);
    return bufferImage;
  } catch (error) {
    throw error
  }
}

inside patient.action.ts

export const registerPatient = async({ identificationDocument, ...patient}: RegisterUserParams) => {
    try {
        let file        
        if(identificationDocument) {
            const docFile =  identificationDocument?.get('blobFile') as File;
            const fileName = identificationDocument?.get('fileName') as string
            const bufferImg: Buffer = await getBufferImage(docFile);
            const inputFile = InputFile.fromBuffer(bufferImg,fileName)            
            file = await storage.createFile(BUCKET_ID!, ID.unique(), inputFile)
        }

        const newPatient = await database.createDocument(
            DATABASE_ID!,
            PATIENT_COLLECTION_ID!,
            ID.unique(),
            { 
                identificationDocumentId: file?.$id ? file.$id : null,
                identificationDocumentUrl: file?.$id ? `${ENDPOINT}/storage/buckets/${BUCKET_ID}/files/${file?.$id}/view?project=${PROJECT_ID}` : null,
                ...patient
            } 
        )
        return parseStringify(newPatient)
        // return 
    } catch (error: any) {
        console.log("Erorr", error);

    }
}

since the InputFile.fromBuffer() and InputFile.fromBlob() were having too many issues to handle on version compatibility. Converting the Blob to Buffer and passing it to storage does the job. If anyone has a better solution let me know :+1:

BerlinWebDev commented 1 month ago

Hey Guys! You just have to the file "use server" at the top of the file do get it work..

MuhamedGamall commented 1 month ago

change your "node-appwrite" version and add this version "node-appwrite": "^12.0.1", Then add this InputFile.fromBlob() instead of InputFile.fromBuffer()

fentahunM commented 1 month ago

instead of InputFile.fromBuffer() use File() constructor as follows it workes for me.

// REGISTER PATIENT export const registerPatient = async ({ identificationDocument, ...patient }: RegisterUserParams) => { try { // Upload file let file; if (identificationDocument) { const inputFile = new File( [identificationDocument?.get("blobFile") as Blob], identificationDocument?.get("fileName") as string );

  file = await storage.createFile(BUCKET_ID!, ID.unique(), inputFile);
}

// Create new patient document
const newPatient = await databases.createDocument(
  DATABASE_ID!,
  PATIENT_COLLECTION_ID!,
  ID.unique(),
  {
    identificationDocumentId: file?.$id ? file.$id : null,
    identificationDocumentUrl: file?.$id
      ? `${ENDPOINT}/storage/buckets/${BUCKET_ID}/files/${file.$id}/view??project=${PROJECT_ID}`
      : null,
    ...patient,
  }
);

return parseStringify(newPatient);

} catch (error) { console.error("An error occurred while creating a new patient:", error); } };

Rufaida-Shaik commented 4 weeks ago

change your "node-appwrite" version and add this version "node-appwrite": "^12.0.1", Then add this InputFile.fromBlob() instead of InputFile.fromBuffer()

THIS WORKED!!!!!!!!!!!!!!! i have been banging my head since two days. re wrote the code fpr multiple times. this works T T. Thanks a ton!