From 93ea63930d774917d459a3e6d914e96afcd003d6 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Fri, 15 Sep 2023 16:02:03 +0100 Subject: [PATCH] due considerations frontend functonality mostly done - trigger update with new aws keys --- .../api/upload/due-considerations/route.ts | 2 +- src/app/due-considerations/page.tsx | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/app/api/upload/due-considerations/route.ts b/src/app/api/upload/due-considerations/route.ts index 4efabc54..9eb58725 100644 --- a/src/app/api/upload/due-considerations/route.ts +++ b/src/app/api/upload/due-considerations/route.ts @@ -45,7 +45,7 @@ export async function POST(request: NextRequest) { }) ); - return new NextResponse(JSON.stringify({ url: preSignedUrls }), { + return new NextResponse(JSON.stringify({ urls: preSignedUrls }), { status: 200, }); } catch (error) { diff --git a/src/app/due-considerations/page.tsx b/src/app/due-considerations/page.tsx index ddf9342b..6b8d81f9 100644 --- a/src/app/due-considerations/page.tsx +++ b/src/app/due-considerations/page.tsx @@ -4,6 +4,43 @@ import { useState } from "react"; import { SelectFolder } from "../components/due-considerations/SelectFolder"; import { Button } from "../shadcn_components/ui/button"; +async function uploadDueConsiderationFiles(files: File[]) { + // Steps: + // 1) For each file, generate a presigned url + // 2) For each file, upload the file to the presigned url + // 3) Trigger the due considerations process + // 4) Profit???? + + // Step 1: Generate presigned URLs + const response = await fetch("/path/to/your/api/endpoint", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + files: files.map((file) => ({ + fileKey: "your/folder/structure/" + file.name, // replace with your actual folder structure + contentType: file.type, + })), + }), + }); + + const { urls } = await response.json(); + + // Step 2: Upload files to S3 + await Promise.all( + files.map((file, index) => { + return fetch(urls[index], { + method: "PUT", + headers: { + "Content-Type": file.type, + }, + body: file, + }); + }) + ); +} + export default function DueConsiderationsHome() { const [files, setFile] = useState([]); const [buttonDisabled, setButtonDisabled] = useState(true);