net-ipfs-engine
net-ipfs-engine copied to clipboard
how to upload file to ipfs and get it from ipfs.
my code below, I upload a file to ipfs, then I want to get the file context, but I get nothing.
public partial class Form1 : Form { IpfsEngine ipfs;
string id;
public Form1()
{
InitializeComponent();
ipfs = new IpfsEngine(new SecureString());
}
private async void UploadData()
{
var options = new AddFileOptions { OnlyHash = true };
var fsn = await ipfs.FileSystem.AddFileAsync("d://temp/1.txt", options);
//var text = await ipfs.FileSystem.ReadAllTextAsync(fsn.Id.ToString());
MessageBox.Show((string)fsn.Id);
id = fsn.Id;
}
private async void GetData()
{
//Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD
string filename = id;
var text = await ipfs.FileSystem.ReadAllTextAsync(filename);
MessageBox.Show(text);
}
private void button1_Click(object sender, EventArgs e)
{
UploadData();
}
private void button2_Click(object sender, EventArgs e)
{
GetData();
}
}
}