forked from PinataCloud/pinata
-
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.
Merge pull request #2 from PinataCloud/feat/add-upload-stream
Feat/add upload stream
- Loading branch information
Showing
5 changed files
with
334 additions
and
94 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 |
---|---|---|
@@ -1,21 +1,18 @@ | ||
import { NextResponse, NextRequest } from "next/server"; | ||
import { pinata } from "@/utils/config"; | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
}, | ||
}; | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
const data = await request.formData(); | ||
const file: File | null = data.get("file") as unknown as File; | ||
const uploadData = await pinata.upload.file(file); | ||
const url = await pinata.gateways.convert(uploadData.IpfsHash); | ||
return NextResponse.json(url, { status: 200 }); | ||
} catch (e) { | ||
console.log(e); | ||
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }); | ||
} | ||
try { | ||
const data = await request.formData(); | ||
const file: File | null = data.get("file") as unknown as File; | ||
const uploadData = await pinata.upload.file(file); | ||
const url = await pinata.gateways.convert(uploadData.IpfsHash); | ||
return NextResponse.json(url, { status: 200 }); | ||
} catch (e) { | ||
console.log(e); | ||
return NextResponse.json( | ||
{ error: "Internal Server Error" }, | ||
{ status: 500 }, | ||
); | ||
} | ||
} |
Oops, something went wrong.