net-ipfs-engine icon indicating copy to clipboard operation
net-ipfs-engine copied to clipboard

how to upload file to ipfs and get it from ipfs.

Open billqu01 opened this issue 1 year ago • 0 comments

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();
    }
}

}

billqu01 avatar Aug 30 '22 14:08 billqu01