-
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
Showing
5 changed files
with
94 additions
and
2 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,30 @@ | ||
import prisma from "@/lib/prisma"; | ||
|
||
export default async function UploadTest() { | ||
const list = await prisma.file.findMany(); | ||
|
||
return ( | ||
<div className="py-4 pt-20 px-12"> | ||
{list.map((e) => ( | ||
<div key={e.id}> | ||
{e.name} | ||
{e.id} | ||
</div> | ||
))} | ||
|
||
<form | ||
action="/api/upload" | ||
encType="multipart/form-data" | ||
method="POST" | ||
className="grid grid-cols-12 gap-6" | ||
> | ||
<input name="file" type="file" id="file"></input> | ||
<div className="ltablet:col-span-6 col-span-12 lg:col-span-6"> | ||
<div className="prose space-y-4 border-muted-200 dark:border-muted-700 dark:bg-muted-800 relative w-full border bg-white transition-all duration-300 rounded-md ptablet:p-8 p-6 lg:p-8"> | ||
<button type="submit">确认</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} |
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,27 @@ | ||
import prisma from "@/lib/prisma"; | ||
|
||
export const revalidate = 60 * 60; | ||
|
||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
try { | ||
const file = await prisma.file.findFirst({ | ||
where: { | ||
name: params.id, | ||
}, | ||
}); | ||
|
||
return new Response(file?.data, { | ||
// headers: { | ||
// "Content-Type": "image/jpeg", | ||
// }, | ||
status: 200, | ||
}); | ||
} catch (error) { | ||
return new Response(`error: ${error.message}`, { | ||
status: 400, | ||
}); | ||
} | ||
} |
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,30 @@ | ||
import prisma from "@/lib/prisma"; | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const text = (await request.formData()).get("file"); | ||
if (text instanceof File) { | ||
console.log(text.name); | ||
|
||
const file = await prisma.file.create({ | ||
data: { | ||
name: text.name, | ||
data: Buffer.from(await text.arrayBuffer()), | ||
mimeType: "", | ||
}, | ||
}); | ||
console.log(file); | ||
} | ||
|
||
console.log(text instanceof File); | ||
// Process the webhook payload | ||
} catch (error) { | ||
return new Response(`Webhook error: ${error.message}`, { | ||
status: 400, | ||
}); | ||
} | ||
|
||
return new Response("Success!", { | ||
status: 200, | ||
}); | ||
} |
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