Skip to content

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

@billqu01

Description

@billqu01

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

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions