Skip to content

Commit

Permalink
cliから適当なパスに置いた画像をipfsにアップロード
Browse files Browse the repository at this point in the history
  • Loading branch information
aowheel committed Oct 3, 2024
1 parent cd6588e commit 3239095
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkgs/cli/src/commands/pinata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Command } from "commander";
import { getJwt, setJwt } from "../services/pinata";
import { PinataSDK } from "pinata-web3";
import path from "path";
import fs from "fs";

export const pinataCommands = new Command();

Expand Down Expand Up @@ -109,3 +111,22 @@ pinataCommands
console.log("URI:", `ipfs://${upload.IpfsHash}`);
}
);

/**
* 画像をipfsにアップロードするコマンド
*/
pinataCommands
.command("uploadImage")
.description("Upload image on ipfs")
.requiredOption("--imagePath <path>", "Path to image")
.action(async ({ imagePath }) => {
const { jwt } = getJwt();

const pinata = new PinataSDK({ pinataJwt: jwt });
const currentDir = process.cwd();
const absPath = path.join(currentDir, imagePath);
const stream = fs.createReadStream(absPath);
const upload = await pinata.upload.stream(stream);

console.log("CID:", upload.IpfsHash);
});
Binary file added pkgs/cli/src/image/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3239095

Please sign in to comment.