Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add file type-specific size limits

Marc Seitz60f1e4b963a1
diff --git a/components/document-upload.tsx b/components/document-upload.tsx
index b1aef508..5d8d209e 100644
--- a/components/document-upload.tsx
+++ b/components/document-upload.tsx
@@ -14,7 +14,9 @@ const fileSizeLimits: { [key: string]: number } = {
"application/vnd.ms-excel": 40, // 40 MB
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": 40, // 40 MB
"application/vnd.oasis.opendocument.spreadsheet": 40, // 40 MB
- "text/csv": 40, // 40 MB
+ "image/png": 100, // 100 MB
+ "image/jpeg": 100, // 100 MB
+ "image/jpg": 100, // 100 MB
};
export default function DocumentUpload({
diff --git a/components/upload-zone.tsx b/components/upload-zone.tsx
index 06ec7ab8..7923b8d0 100644
--- a/components/upload-zone.tsx
+++ b/components/upload-zone.tsx
@@ -21,6 +21,15 @@ interface FileWithPath extends File {
path?: string;
}
+const fileSizeLimits: { [key: string]: number } = {
+ "application/vnd.ms-excel": 40, // 40 MB
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": 40, // 40 MB
+ "application/vnd.oasis.opendocument.spreadsheet": 40, // 40 MB
+ "image/png": 100, // 100 MB
+ "image/jpeg": 100, // 100 MB
+ "image/jpg": 100, // 100 MB
+};
+
export default function UploadZone({
children,
onUploadStart,
@@ -76,6 +85,8 @@ export default function UploadZone({
const uploadPromises = acceptedFiles.map(async (file, index) => {
const path = (file as any).path || file.webkitRelativePath || file.name;
+
+ // count the number of pages in the file
let numPages = 1;
if (file.type === "application/pdf") {
const buffer = await file.arrayBuffer();
@@ -96,6 +107,23 @@ export default function UploadZone({
}
}
+ // check dynamic file size
+ const fileType = file.type;
+ const fileSizeLimit = fileSizeLimits[fileType] * 1024 * 1024;
+ if (file.size > fileSizeLimit) {
+ setUploads((prev) =>
+ prev.filter((upload) => upload.fileName !== file.name),
+ );
+
+ return setRejectedFiles((prev) => [
+ {
+ fileName: file.name,
+ message: `File size too big (max. ${fileSizeLimit} MB)`,
+ },
+ ...prev,
+ ]);
+ }
+
const { complete } = await resumableUpload({
file, // File
onProgress: (bytesUploaded, bytesTotal) => {