Skip to content

Commit

Permalink
fininsh upload and download file test,update has a bug that hash will…
Browse files Browse the repository at this point in the history
… not display on webui
  • Loading branch information
mapkkkk committed Jun 26, 2024
1 parent 34f4599 commit e9980c8
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 15 deletions.
28 changes: 17 additions & 11 deletions src/main/java/chain/min/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 3,27 @@
import java.io.IOException;

public class Main {
String serverIP = "192.168.31.208";
int serverPort = 5001;
String uploadFilePath = "D:\\code\\ipfs\\ipfs\\test\\upload\\uploadtest.txt";
String downloadFileHash = "QmRZtguPjYdrDDZ6V2BrsUKfZoptoVPqbyYxzbZD5Wj2sz";
String downloadDst = "D:\\code\\ipfs\\ipfs\\test\\download\\downloadRes.txt";

fileOperation fileOp = new fileOperation();

public void main() throws IOException {
public static void fileTest() throws IOException {
fileOperation fileOp = new fileOperation();
String serverIP = "192.168.31.208";
int serverPort = 5001;
String uploadFilePath = "D:\\code\\ipfs\\ipfs\\test\\upload\\uploadtest.txt";
String downloadFileHash = "QmRZtguPjYdrDDZ6V2BrsUKfZoptoVPqbyYxzbZD5Wj2sz";
String downloadDst = "D:\\code\\ipfs\\ipfs\\test\\download\\downloadRes.txt";
// 连接服务器
fileOp.initIPFS(this.serverIP, this.serverPort);
fileOp.initIPFS(serverIP, serverPort);
// 上传
String uploadHashRes = fileOp.uploadFile(this.uploadFilePath);
String uploadHashRes = fileOp.uploadFile(uploadFilePath);
System.out.println("uploadHashRes is: " uploadHashRes);
// 下载
fileOp.downloadFile(this.downloadFileHash, this.downloadDst);
// fileOp.downloadFile(downloadFileHash, downloadDst);
}
public static void main(String[] args) {
try {
fileTest();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
5 changes: 1 addition & 4 deletions src/main/java/chain/min/fileOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 15,7 @@ public class fileOperation implements fileOperationInterface {

public void initIPFS(String ipfsAddress, int port) {
//初始化ipfs节点
String ipfsUrl = "http://" ipfsAddress ":" port;
//创建ipfs节点连接
MultiAddress multiaddr = new MultiAddress(ipfsUrl);
this.ipfsHandle = new IPFS(multiaddr);
this.ipfsHandle = new IPFS(ipfsAddress, port);
System.out.println("IPFS node initialized successfully.");
}

Expand Down
Loading

0 comments on commit e9980c8

Please sign in to comment.