What is the best practice to upload file using multer and create a record in Prisma

Recently I have been obsessed with uploading files with trpc, I have files that I do not want to keep on the cloud server and I want to keep them locally. I've done the uploads with Multer, but how do I associate them to my Prisma, for example Patient table? What is the best practice for this situation?
11 Replies
Çağlar
ÇağlarOP3y ago
I was wondering if I could do something like const upload = trpc.file.upload.useMutation() and then inside the function await upload.mutateAsync(file)
Çağlar
ÇağlarOP3y ago
One more question, should the File schema be associated with the User schema or the Post schema in file uploads? Any idea?
julius
julius3y ago
trpc currently only supports json content type but we want to support other content types later
Çağlar
ÇağlarOP3y ago
@julius maybe only file infos? i.e. is it ok for me to just keep the file information and call them?
julius
julius3y ago
Not sure what you mean by that
Çağlar
ÇağlarOP3y ago
Let me explain, I save my files to local via multer with next api, at the same time, I want to keep the file information in my database while saving and associate them with the user or the post. Do you think this is the right approach?
hakkub
hakkub3y ago
i would recommend using something like S3. Moreover if you're hosting on vercel, using presigned url's to get aroud the 5mb max upload size.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Çağlar
ÇağlarOP3y ago
The files to be uploaded contain high confidentiality, patient records etc. Also thanks for the info So how do you associate uploaded files with users or posts?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Çağlar
ÇağlarOP3y ago
@SpudMaster amazing, thank you for help

Did you find this page helpful?