+
+ 404 File Not Found
+ Could not find the requested attachment.
+
+ Go Back
+
+
+ );
+}
\ No newline at end of file
diff --git a/app/attachment/[id]/route.tsx b/app/attachment/[id]/route.tsx
new file mode 100644
index 0000000..866b557
--- /dev/null
+++ b/app/attachment/[id]/route.tsx
@@ -0,0 +1,27 @@
+import { fetchBillById } from '@/app/lib/fetchBillById';
+import { notFound } from 'next/navigation';
+
+export async function GET(request: Request, { params:{ id } }: { params: { id:string } }) {
+ const [invoiceID, billID] = id.split('-');
+
+ const bill = await fetchBillById(invoiceID, billID);
+
+ if(!bill?.attachment) {
+ notFound();
+ }
+
+ // convert fileContentsBase64 from Base64 string to binary string
+ const fileContentsBuffer = Buffer.from(bill.attachment.fileContentsBase64, 'base64');
+
+ // convert fileContentsBuffer to format that can be sent to the client
+ const fileContents = new Uint8Array(fileContentsBuffer);
+
+ return new Response(fileContents, {
+ status: 200,
+ headers: {
+ 'Content-Type': "application/octet-stream",
+ 'Content-Disposition': `attachment; filename="${bill.attachment.fileName}"`,
+ 'Last-Modified': `${bill.attachment.fileLastModified}`
+ }
+ });
+}
\ No newline at end of file
diff --git a/app/bills/[id]/edit/page.tsx b/app/bills/[id]/edit/page.tsx
index 85a120b..1525e25 100644
--- a/app/bills/[id]/edit/page.tsx
+++ b/app/bills/[id]/edit/page.tsx
@@ -1,38 +1,10 @@
import { PlainLocation, PlainBill, MongoLocation } from '@/app/lib/db-types';
+import { fetchBillById } from '@/app/lib/fetchBillById';
import clientPromise from '@/app/lib/mongodb';
import { BillEditForm } from '@/app/ui/BillEditForm';
import { ObjectId } from 'mongodb';
import { notFound } from 'next/navigation';
-const fetchBillById = async (locationID:string, billID:string) => {
- const client = await clientPromise;
- const db = client.db("rezije");
-
- // find a location with the given locationID
- const billLocation = await db.collection