forked from ucbepic/docetl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b79fe5f
commit d7e9dfe
Showing
11 changed files
with
294 additions
and
249 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { writeFile } from "fs/promises"; | ||
import path from "path"; | ||
import { mkdir } from "fs/promises"; | ||
import os from "os"; | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
const formData = await request.formData(); | ||
const file = formData.get("file") as File; | ||
|
||
if (!file) { | ||
return NextResponse.json({ error: "No file uploaded" }, { status: 400 }); | ||
} | ||
|
||
// Convert the file to buffer | ||
const bytes = await file.arrayBuffer(); | ||
const buffer = Buffer.from(bytes); | ||
|
||
// Create uploads directory in user's home directory if it doesn't exist | ||
const uploadDir = path.join(os.homedir(), ".docetl", "files"); | ||
await mkdir(uploadDir, { recursive: true }); | ||
|
||
// Create full file path | ||
const filePath = path.join(uploadDir, file.name); | ||
|
||
// Write the file | ||
await writeFile(filePath, buffer); | ||
|
||
// Return the absolute path | ||
return NextResponse.json({ path: filePath }); | ||
} catch (error) { | ||
console.error("Error uploading file:", error); | ||
return NextResponse.json( | ||
{ error: "Failed to upload file" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
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
Oops, something went wrong.