-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UI and Backend): Started implementing file upload logic [2024-10…
…-27]
- Loading branch information
1 parent
82adb76
commit 3918108
Showing
4 changed files
with
221 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { NextRequest } from "next/server"; | ||
|
||
// Hardcoded auth token - replace with your actual token | ||
const HARDCODED_AUTH_TOKEN = ""; | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
const formData = await request.formData(); | ||
const file = formData.get("file"); | ||
|
||
if (!file || !(file instanceof File)) { | ||
return new Response( | ||
JSON.stringify({ | ||
success: false, | ||
error: "No file provided", | ||
}), | ||
{ status: 400 }, | ||
); | ||
} | ||
|
||
// Create a new FormData for the API call | ||
const apiFormData = new FormData(); | ||
apiFormData.append("file", file); | ||
|
||
// Hardcoded values | ||
apiFormData.append("workspace_id", ""); | ||
apiFormData.append("name", "my-awesome-layer"); | ||
|
||
const response = await fetch("http://localhost:3001/upload_layer", { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${HARDCODED_AUTH_TOKEN}`, | ||
}, | ||
body: apiFormData, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error("Upload failed"); | ||
} | ||
|
||
const data = await response.json(); | ||
return new Response(JSON.stringify({ success: true, data }), { | ||
status: 200, | ||
}); | ||
} catch (error) { | ||
console.error("Upload error:", error); | ||
return new Response( | ||
JSON.stringify({ | ||
success: false, | ||
error: "Upload failed", | ||
}), | ||
{ status: 500 }, | ||
); | ||
} | ||
} | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters