Skip to content

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

feat: limit file size for excel docs

Marc Seitzd9b838e4ccf3
diff --git a/components/document-upload.tsx b/components/document-upload.tsx
index bf4e6d41..321bb8a5 100644
--- a/components/document-upload.tsx
+++ b/components/document-upload.tsx
@@ -1,6 +1,5 @@
import { useMemo, useState } from "react";
-import { useTeam } from "@/context/team-context";
import {
Upload as ArrowUpTrayIcon,
File as DocumentIcon,
@@ -16,6 +15,13 @@ import { usePlan } from "@/lib/swr/use-billing";
import { bytesToSize } from "@/lib/utils";
import { getPagesCount } from "@/lib/utils/get-page-number-count";
+const fileSizeLimits: { [key: string]: number } = {
+ "application/vnd.ms-excel": 100, // 30 MB
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": 30, // 30 MB
+ "text/csv": 30, // 30 MB
+ "application/vnd.oasis.opendocument.spreadsheet": 30, // 30 MB
+};
+
function fileIcon(fileType: string) {
switch (fileType) {
case "application/pdf":
@@ -32,6 +38,8 @@ function fileIcon(fileType: string) {
return <PresentationChartBarIcon className="mx-auto h-6 w-6" />;
case "application/vnd.ms-excel":
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
+ case "text/csv":
+ case "application/vnd.oasis.opendocument.spreadsheet":
return <FileSpreadsheetIcon className="mx-auto h-6 w-6" />;
default:
return <DocumentIcon className="mx-auto h-6 w-6" />;
@@ -59,6 +67,16 @@ export default function DocumentUpload({
maxSize: maxSize * 1024 * 1024, // 30 MB
onDropAccepted: (acceptedFiles) => {
const file = acceptedFiles[0];
+ const fileType = file.type;
+ const fileSizeLimit = fileSizeLimits[fileType] * 1024 * 1024;
+
+ if (file.size > fileSizeLimit) {
+ toast.error(
+ `File size too big for ${fileType} (max. ${fileSizeLimits[fileType]} MB)`,
+ );
+ return;
+ }
+
if (file.type !== "application/pdf") {
setCurrentFile(file);
return;