-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up Pinata Cloud Storage Interaction Successfully (#98)
- Loading branch information
Showing
5 changed files
with
38 additions
and
1 deletion.
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
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,18 @@ | ||
import { NextResponse, type NextRequest } from "next/server"; | ||
import { pinata } from '../../../utils/pinata' | ||
|
||
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 } | ||
); | ||
} | ||
} |
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,15 @@ | ||
"server only" | ||
|
||
import { PinataSDK } from 'pinata-web3' | ||
|
||
export const pinata = new PinataSDK({ | ||
pinataJwt: `${process.env.PINATA_JWT}`, | ||
pinataGateway: `${process.env.NEXT_PUBLIC_GATEWAY_URL}` | ||
}) | ||
|
||
// To get the client side form implementation of file uploads to pinata: | ||
// Visit the url: https://docs.pinata.cloud/frameworks/next-js-ipfs#create-client-side-form | ||
|
||
// If file size limitation is crossed consistently and there is need to upload more than the limit | ||
// then this implementation can be changed to follow the guide: | ||
// https://www.pinata.cloud/blog/how-to-upload-to-ipfs-from-the-frontend-with-signed-jwts/ |