Overview
PyqDeck uses UploadThing for handling file uploads. This service provides a secure way to upload files directly from the client (or via the backend) to a cloud storage provider (like AWS S3) without managing the infrastructure or complex multipart parsing yourself.Configuration
The system is configured inbackend/src/utils/uploadthing.js.
File Rules
- Allowed Types:
pdfonly. - Max File Size:
16MB. - Max File Count:
1per request.
Upload Flow
The “pdfUploader” flow consists of two main stages:1. Middleware (Pre-upload)
Before the file is sent to UploadThing, our server verifies the user’s session using Clerk.clerkId is stored as metadata and passed to the next stage.
2. onUploadComplete (Post-upload)
Once the file is successfully stored in UploadThing’s cloud, they trigger a webhook back to our server.- Look up User: We use the
clerkIdfrom the metadata to find the internal MongoDBUserID. - Save Record: We create a new entry in the
Uploadcollection in MongoDB.
Data Model (Upload.js)
Each upload is tracked with the following fields:
url: The public URL to access the file.publicId: The unique key provided by UploadThing (useful for deletions).mimeType: Alwaysapplication/pdffor now.size: File size in bytes.uploadedBy: Reference to theUserwho performed the upload.
Integration
Uploads are primarily used when creating or updatingPaper records. The Upload.id is linked to the paper, allowing users to view the original PDF source.
Environment Variables
| Variable | Description |
|---|---|
UPLOADTHING_SECRET | Secret key from the UploadThing dashboard. |
UPLOADTHING_APP_ID | App ID from the UploadThing dashboard. |

