forked from mito-systems/sol-mem-gen
Add script to upload image to Pinata
This commit is contained in:
parent
ff48bdb954
commit
371a140419
2081
package-lock.json
generated
2081
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "ts-node --project tsconfig.server.json server.ts",
|
||||
"upload-image": "ts-node --project tsconfig.server.json upload-image-to-pinata.ts",
|
||||
"build": "next build",
|
||||
"start": "tsc --project tsconfig.server.json && NODE_ENV=production PORT=80 node dist/server.js",
|
||||
"lint": "next lint"
|
||||
@ -18,6 +19,7 @@
|
||||
"dotenv": "^16.4.7",
|
||||
"next": "13.5.4",
|
||||
"openai": "^4.77.0",
|
||||
"pinata-web3": "^0.5.4",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"sqlite3": "^5.1.7",
|
||||
|
@ -9,5 +9,5 @@
|
||||
"isolatedModules": false,
|
||||
"noEmit": false
|
||||
},
|
||||
"include": ["server.ts"]
|
||||
"include": ["server.ts", "upload-image-to-pinata.ts"]
|
||||
}
|
34
upload-image-to-pinata.ts
Normal file
34
upload-image-to-pinata.ts
Normal file
@ -0,0 +1,34 @@
|
||||
// import { PinataSDK } from "pinata";
|
||||
import { PinataSDK } from "pinata-web3";
|
||||
import fs from 'fs';
|
||||
|
||||
async function main (): Promise<void> {
|
||||
const pinata = new PinataSDK({
|
||||
pinataJwt: "<pinata-jwt>",
|
||||
pinataGateway: "pinata-gateway",
|
||||
});
|
||||
|
||||
try {
|
||||
// const file = new File(["hello world"], "Testing.txt", { type: "text/plain" });
|
||||
|
||||
// const imageBuffer = fs.readFileSync('meme.png');
|
||||
// const file = new File([imageBuffer], "meme.png", { type: "image/png" });
|
||||
|
||||
const imageUrl = 'https://fal.media/files/elephant/U5kmZoEsQdBx8r7oyBo8C.png';
|
||||
const upload = await pinata.upload.url(imageUrl);
|
||||
console.log(upload);
|
||||
|
||||
console.log("Files on account:", await pinata.listFiles())
|
||||
|
||||
const publicURL = await pinata.gateways.convert(upload.IpfsHash);
|
||||
console.log('publicURL', publicURL)
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
console.log("Files on account:", await pinata.listFiles())
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
});
|
Loading…
Reference in New Issue
Block a user