how do I get the Files/Images in my Next.js project? #34
-
I am able to upload the images/files with the upload button, but I am finding it hard to get those images back and display them using the {
id: '01925bf9-a199-7ca1-a77c-6f015bc054b5',
name: 'Screenshot (569).png',
cid: 'bafkreihtr7sk3ai4u6q6coaap2feckejs4auwjravb4gwzejhqmrqqzx4m',
size: 83457,
number_of_files: 1,
mime_type: 'image/png',
group_id: null,
keyvalues: {},
created_at: '2024-10-05T09:19:02.125793Z'
}, TIA |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Great question! If you're using the Files API all files are by default private, so in order to access them you need to create a signed URL. You can do this using the import { PinataSDK } from "pinata";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const url = await pinata.gateways.createSignedURL({
cid: "bafkreib4pqtikzdjlj4zigobmd63lig7u6oxlug24snlr6atjlmlza45dq",
expires: 30, // Number of seconds link is valid for
}); Alternatively, if you want the file to be publicly accessible, you can do the following:
import { PinataSDK } from "pinata";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const group = await pinata.groups.create({
name: "My New Group",
isPublic: true
});
const upload = await pinata.upload
.file(file)
.group(group.id)
If you follow the Next.js guide it goes over a flow for uploading and creating a signed url in one step which you can check out here! |
Beta Was this translation helpful? Give feedback.
-
thanks @stevedylandev it's working, |
Beta Was this translation helpful? Give feedback.
Great question! If you're using the Files API all files are by default private, so in order to access them you need to create a signed URL. You can do this using the
cid
from the file upload like so:Alternatively, if you want the file to be publicly accessible, you can do the following: