After I submit the register patient form, the get started button is loading infinitely.
I found out that's because it hangs inside the storage.createFile function in the patient server action.
I placed debug console logs before and after the storage.createFile function. The one before printed out (that one from InputFile.fromBlob) and the one after it didn't. The file wasn't also placed into the bucket. What's wrong?
#Register Patient Form - Stuck in storage.createFile
21 messages · Page 1 of 1 (latest)
check the storage settings on your Appwrite, and try changing the maximum file size. On my Appwrite, I changed it to 10MB.
and share your patient.actions.ts and RegisterForm.tsx code
// patient.actions.ts
"use server";
import { ID, InputFile, Query } from "node-appwrite";
import { BUCKET_ID, DATABASE_ID, databases, ENDPOINT, PATIENT_COLLECTION_ID, PROJECT_ID, storage, users } from "../appwrite.config";
import { parseStringify } from "../utils";
export const createUser = async (user: CreateUserParams) => {
try {
const newUser = await users.create(
ID.unique(),
user.email,
user.phone,
undefined,
user.name
);
console.log({ newUser });
return parseStringify(newUser);
} catch (error: any) {
if (error && error?.code == 409) {
const documents = await users.list([
Query.equal('email', [user.email])
]);
return documents?.users[0];
}
}
}
export const getUser = async (userId: string) => {
try {
const user = await users.get(userId);
return parseStringify(user);
} catch (error) {
console.log(error);
}
}
export const registerPatient = async ({ identificationDocument, ...patient }: RegisterUserParams) => {
try {
let file;
if (identificationDocument) {
const inputFile =
identificationDocument &&
InputFile.fromBlob(
identificationDocument?.get("blobFile") as Blob,
identificationDocument?.get("fileName") as string
);
file = await storage.createFile(BUCKET_ID!, ID.unique(), inputFile);
}
const newPatient = await databases.createDocument(
DATABASE_ID!,
PATIENT_COLLECTION_ID!,
ID.unique(),
{
identificationDocumentId: file?.$id || null,
identificationDocumentUrl: `${ENDPOINT}/storage/buckets/${BUCKET_ID}/files/${file?.$id}/view?project=${PROJECT_ID}`,
...patient,
}
);
return parseStringify(newPatient);
} catch (error) {
console.log(error);
}
}
//register form.tsx
Updating the maximum file size didn't really help, it still just hangs there...
Ah, it seems I found the problem
You imported InputFile incorrectly. It should be imported from "node-appwrite/file"
"Cannot find module 'node-appwrite/file' or its corresponding type declarations.ts(2307)
Error #1 (ts 2307)
Cannot find module
node-appwrite/file
or its corresponding type declarations"
My VS Code complains about that.
Then maybe the problem is in your dependency version. Here is my package.json
{
"name": "careplus",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-alert-dialog": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-radio-group": "^1.2.0",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@tanstack/react-table": "^8.19.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"input-otp": "^1.2.4",
"lucide-react": "^0.400.0",
"next": "14.2.4",
"next-themes": "^0.3.0",
"node-appwrite": "^13.0.0",
"react": "^18",
"react-datepicker": "^7.2.0",
"react-dom": "^18",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.52.1",
"react-phone-number-input": "^3.4.3",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.4",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
It stopped hanging, but it now throws some sort of exception:
AppwriteException: Client Closed Request
at ......
{
code: 499,
type: '',
response: { message: 'Client Closed Request' }
}
The file is also not saved in the bucket.
hmm weird, could you please share your GitHub repository so I can try it out?
ok im checking now
Hi, I have tried your code locally and everything is working fine. I was able to upload documents and successfully register a patient using my env. There might be a configuration error with your Appwrite setup. To make sure, I will send my .env file to you via dm. Please try using my .env.local file. If there are no errors after using my env, please double-check your Appwrite configuration
It works with your .env.local, but not with mine.
I double checked all the keys, but they are basically correct, and I have no clue where the issue might be in the configuration of the Appwrite dashboard, because it has problems with file uploading and I double checked it like 15 times.
Can you manually upload your file through the following menu to your bucket?
If using my env doesn't cause any issues, then no problem with your code, likely a problem with your Appwrite setup. I suggest creating a new Appwrite account with a new email to ensure everything is set up correctly
How about your patient collection? Could you screenshot the list of attributes for your patient collection