due considerations frontend functonality mostly done - trigger update with new aws keys

This commit is contained in:
Khalim Conn-Kowlessar 2023-09-15 16:02:03 +01:00
parent fd7c1578ef
commit 93ea63930d
2 changed files with 38 additions and 1 deletions

View file

@ -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) {

View file

@ -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<File[]>([]);
const [buttonDisabled, setButtonDisabled] = useState(true);