给定 rust 的绝对路径,如何上传文件?
How do I upload a file given its absolute path in rust?
我的 objective 是使用 Rust 编程语言在 ipfs.io 上上传文件。我正在启动一个命令行工具来执行此操作,并且该命令本身可以运行,但是当使用 Rust 实现时,它会失败。
实际命令为:
➜ ~ ipfs add ~/dev/learning-rust/upload-file-to-ipfs/src/main.rs
added QmPUGDCiLvjEiETVDVMHqgJ8xxtQ5Hu7YEMzFqRfE8vDfq main.rs
现在,我的 Rust 代码是:
use std::io;
use std::process::Command;
fn main() {
// ask user to provide the file path to be uploaded on ipfs
println!("Please enter the file path to upload on IPFS: ");
let mut file_path = String::new();
io::stdin()
.read_line(&mut file_path)
.expect("Failed to read temperature.");
// uploading a file
let output = Command::new("ipfs")
.arg("add")
.arg(file_path)
.output()
.expect("ipfs command failed to start");
println!("Output is: {:?}", output);
// println!("The hash digest is: {:?}", output.stdout);
}
失败并出现以下错误:
Output is: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Error: lstat /Users/aviralsrivastava/dev/learning-rust/upload-file-to-ipfs/src/main.rs\n: no such file or directory\n\nUSAGE\n ipfs add <path>... - Add a file or directory to ipfs.\n\n ipfs add [--recursive | -r] [--quiet | -q] [--quieter | -Q] [--silent] [--progress | -p] [--trickle | -t] [--only-hash | -n] [--wrap-with-directory | -w] [--hidden | -H] [--chunker=<chunker> | -s] [--pin=false] [--raw-leaves] [--nocopy] [--fscache] [--cid-version=<cid-version>] [--] <path>...\n\n Adds contents of <path> to ipfs. Use -r to add directories (recursively).\n\nUse \'ipfs add --help\' for more information about this command.\n\n" }
我参考了 this to answer and read the official documentation,都是徒劳的。
如何在给定绝对 and/or 相对路径和 return 打印语句中的散列的情况下上传文件?
我的 objective 是使用 Rust 编程语言在 ipfs.io 上上传文件。我正在启动一个命令行工具来执行此操作,并且该命令本身可以运行,但是当使用 Rust 实现时,它会失败。
实际命令为:
➜ ~ ipfs add ~/dev/learning-rust/upload-file-to-ipfs/src/main.rs
added QmPUGDCiLvjEiETVDVMHqgJ8xxtQ5Hu7YEMzFqRfE8vDfq main.rs
现在,我的 Rust 代码是:
use std::io;
use std::process::Command;
fn main() {
// ask user to provide the file path to be uploaded on ipfs
println!("Please enter the file path to upload on IPFS: ");
let mut file_path = String::new();
io::stdin()
.read_line(&mut file_path)
.expect("Failed to read temperature.");
// uploading a file
let output = Command::new("ipfs")
.arg("add")
.arg(file_path)
.output()
.expect("ipfs command failed to start");
println!("Output is: {:?}", output);
// println!("The hash digest is: {:?}", output.stdout);
}
失败并出现以下错误:
Output is: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Error: lstat /Users/aviralsrivastava/dev/learning-rust/upload-file-to-ipfs/src/main.rs\n: no such file or directory\n\nUSAGE\n ipfs add <path>... - Add a file or directory to ipfs.\n\n ipfs add [--recursive | -r] [--quiet | -q] [--quieter | -Q] [--silent] [--progress | -p] [--trickle | -t] [--only-hash | -n] [--wrap-with-directory | -w] [--hidden | -H] [--chunker=<chunker> | -s] [--pin=false] [--raw-leaves] [--nocopy] [--fscache] [--cid-version=<cid-version>] [--] <path>...\n\n Adds contents of <path> to ipfs. Use -r to add directories (recursively).\n\nUse \'ipfs add --help\' for more information about this command.\n\n" }
我参考了 this to answer and read the official documentation,都是徒劳的。
如何在给定绝对 and/or 相对路径和 return 打印语句中的散列的情况下上传文件?