Skip to content

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

feat: allow excel sheet upload

Marc Seitz1f1cb1d6cc71
diff --git a/components/document-upload.tsx b/components/document-upload.tsx
index 21ae5905..ef55e876 100644
--- a/components/document-upload.tsx
+++ b/components/document-upload.tsx
@@ -5,6 +5,7 @@ import {
Upload as ArrowUpTrayIcon,
File as DocumentIcon,
FileText as DocumentTextIcon,
+ FileSpreadsheetIcon,
Image as PhotoIcon,
Presentation as PresentationChartBarIcon,
} from "lucide-react";
@@ -29,6 +30,9 @@ function fileIcon(fileType: string) {
case "application/vnd.ms-powerpoint":
case "application/msword":
return <PresentationChartBarIcon className="mx-auto h-6 w-6" />;
+ case "application/vnd.ms-excel":
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
+ return <FileSpreadsheetIcon className="mx-auto h-6 w-6" />;
default:
return <DocumentIcon className="mx-auto h-6 w-6" />;
}
@@ -46,11 +50,17 @@ export default function DocumentUpload({
const { getRootProps, getInputProps } = useDropzone({
accept: {
"application/pdf": [], // ".pdf"
+ "application/vnd.ms-excel": [], // ".xls"
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx"
},
multiple: false,
maxSize: maxSize * 1024 * 1024, // 30 MB
onDropAccepted: (acceptedFiles) => {
const file = acceptedFiles[0];
+ if (file.type !== "application/pdf") {
+ setCurrentFile(file);
+ return;
+ }
file
.arrayBuffer()
.then((buffer) => {
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 416d68da..52a06628 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -199,7 +199,7 @@ export default function LinksTable({
>
{/* Progress bar */}
{primaryVersion &&
- primaryVersion.type !== "notion" &&
+ primaryVersion.type === "pdf" &&
!primaryVersion.hasPages ? (
<ProcessStatusBar
documentVersionId={primaryVersion.id}
diff --git a/lib/files/put-file.ts b/lib/files/put-file.ts
index 279a5ec0..e37d410d 100644
--- a/lib/files/put-file.ts
+++ b/lib/files/put-file.ts
@@ -65,8 +65,14 @@ const putFileInS3 = async ({
docId = newId("doc");
}
- if (file.type !== "application/pdf") {
- throw new Error("Only PDF files are supported");
+ if (
+ ![
+ "application/pdf",
+ "application/vnd.ms-excel",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ ].includes(file.type)
+ ) {
+ throw new Error("Only PDF and Excel files are supported");
}
const presignedResponse = await fetch(
@@ -110,8 +116,11 @@ const putFileInS3 = async ({
);
}
- const body = await file.arrayBuffer();
- const numPages = await getPagesCount(body);
+ let numPages: number = 1;
+ if (file.type === "application/pdf") {
+ const body = await file.arrayBuffer();
+ numPages = await getPagesCount(body);
+ }
return {
type: DocumentStorageType.S3_PATH,
diff --git a/pages/api/file/browser-upload.ts b/pages/api/file/browser-upload.ts
index 4723fb33..9f4ed144 100644
--- a/pages/api/file/browser-upload.ts
+++ b/pages/api/file/browser-upload.ts
@@ -47,7 +47,11 @@ export default async function handler(
}
return {
- allowedContentTypes: ["application/pdf"],
+ allowedContentTypes: [
+ "application/pdf",
+ "application/vnd.ms-excel",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ ],
maximumSizeInBytes: maxSize, // 30 MB
metadata: JSON.stringify({
// optional, sent to your server on upload completion
diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.ts
index 8cb96094..b721bebc 100644
--- a/pages/api/teams/[teamId]/documents/index.ts
+++ b/pages/api/teams/[teamId]/documents/index.ts
@@ -152,8 +152,8 @@ export default async function handle(
},
});
- // skip triggering convert-pdf-to-image job for "notion" documents
- if (type !== "notion") {
+ // skip triggering convert-pdf-to-image job for "notion" / "excel" documents
+ if (type === "pdf") {
// trigger document uploaded event to trigger convert-pdf-to-image job
await client.sendEvent({
id: document.versions[0].id, // unique eventId for the run
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 93fd700a..3df31e34 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -124,7 +124,7 @@ model Document {
name String
description String?
file String // This should be a reference to where the file is stored (S3, Google Cloud Storage, etc.)
- type String? // This should be a reference to the file type (pdf, docx, etc.)
+ type String? // This should be a reference to the file type (pdf, xlsx, etc.)
storageType DocumentStorageType @default(VERCEL_BLOB)
numPages Int? // This should be a reference to the number of pages in the document
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)