Skip to content

Commit

Permalink
Merge pull request #2 from PinataCloud/feat/add-upload-stream
Browse files Browse the repository at this point in the history
Feat/add upload stream
  • Loading branch information
stevedylandev authored Sep 30, 2024
2 parents 151855f + 26b105f commit 89fc9e3
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 94 deletions.
29 changes: 13 additions & 16 deletions examples/next-starter/app/api/files/route.ts
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 },
);
}
}
Loading

0 comments on commit 89fc9e3

Please sign in to comment.