richardschneider / net-ipfs-http-client

InterPlanetary File System client for .Net (C#, VB, F# ...)
MIT License
158 stars 52 forks source link

Error while using IpfsClient.FileSystem.AddTextAsync #40

Closed Jawadlord closed 5 years ago

Jawadlord commented 5 years ago

I am trying to add the files to the IPFS, (I am not running any local node). I can get the files from IPFS but I cant upload/add any text or file.

READING FILE FROM IPFS.IO (working fine) IpfsClient ipfs = new IpfsClient("https://ipfs.io/ipfs"); var file = await ipfs.FileSystem.ReadFileAsync("QmSRrpQ8H1RyhSvprZBUrQrkLUSq5XdyX8KdfpxJZgK2mx"); Image image = Bitmap.FromStream(file);

ADD FILE/TEXT TO IPFS IpfsClient ipfs = new IpfsClient("https://ipfs.io/ipfs"); var result = await ipfs.FileSystem.AddTextAsync("HelloWorld"); >> gives me following error

System.Net.Http.HttpRequestException: 'Invalid IPFS command: https://ipfs.io/api/v0/add?chunker=size-262144'

You can check this in any C# application (winforms/xamarin android) all gives me the same error.

Please suggest. Thanks

Jawadlord commented 5 years ago

Plus I dont want to any local node running.

richardschneider commented 5 years ago

The IpfsClient is designed to communicate with an IPFS daemon (a server that supports the IPFS HTTP-API protocol). My understanding is that https://ipfs.io/ipfs/x is a service that returns the HTTP representation of x and is not a daemon. Perhaps @diasdavid can shed some light.

I am surprised that the code for reading file from ipfs.io works. I will investigate and get back to you.

Jawadlord commented 5 years ago

Well, actually I believe its just using HttpWebRequest and HttpWebResponse methods for the files and text etc. Since getting the file is just like normal GetResponse, it reads the file from the host we provide. Having said that, means that Adding the file can also be possible.

Jawadlord commented 5 years ago

Also please let me know if you have any other solution for uploading the files to IPFS without using local node. Thanks

richardschneider commented 5 years ago

I suggest you ask https://discuss.ipfs.io/ for a solution.

shamtroon commented 3 years ago

I am trying to add the files to the IPFS, (I am not running any local node). I can get the files from IPFS but I cant upload/add any text or file.

READING FILE FROM IPFS.IO (working fine) IpfsClient ipfs = new IpfsClient("https://ipfs.io/ipfs"); var file = await ipfs.FileSystem.ReadFileAsync("QmSRrpQ8H1RyhSvprZBUrQrkLUSq5XdyX8KdfpxJZgK2mx"); Image image = Bitmap.FromStream(file);

ADD FILE/TEXT TO IPFS IpfsClient ipfs = new IpfsClient("https://ipfs.io/ipfs"); var result = await ipfs.FileSystem.AddTextAsync("HelloWorld"); >> gives me following error

System.Net.Http.HttpRequestException: 'Invalid IPFS command: https://ipfs.io/api/v0/add?chunker=size-262144'

You can check this in any C# application (winforms/xamarin android) all gives me the same error.

Please suggest. Thanks

+1 Same issue I am facing, have you resolve this issue ? or any workaround @richardschneider @Jawadlord

Jawadlord commented 3 years ago

Hi @shamtroon, I resolved that by using IPFS Infura URL. Can't believe still there is no working solution for this code snippet. Anyway below is my working code

                 //Upload to IPFS
                Ipfs.Api.IpfsClient ipfs = new Ipfs.Api.IpfsClient("https://ipfs.infura.io:5001");
                var fileResult = await ipfs.FileSystem.AddTextAsync("HelloWorld");
                string ipfsHash = fileResult.Id.Hash.ToString(); 

                //Reading from IPFS
                IpfsClient ipfs = new IpfsClient("https://ipfs.io/ipfs");
                var text = await ipfs.FileSystem.ReadTextAsync(ipfsHash);

                //Or paste the following URL in webbrowser / download string via webclient etc
                "https://ipfs.io/ipfs/" + result.Id.Hash.ToString();

Let me know :)

shamtroon commented 3 years ago

Hi @shamtroon, I resolved that by using IPFS Infura URL. Can't believe still there is no working solution for this code snippet. Anyway below is my working code

                 //Upload to IPFS
                Ipfs.Api.IpfsClient ipfs = new Ipfs.Api.IpfsClient("https://ipfs.infura.io:5001");
                var fileResult = await ipfs.FileSystem.AddTextAsync("HelloWorld");
                string ipfsHash = fileResult.Id.Hash.ToString(); 

                //Reading from IPFS
                IpfsClient ipfs = new IpfsClient("https://ipfs.io/ipfs");
                var text = await ipfs.FileSystem.ReadTextAsync(ipfsHash);

                //Or paste the following URL in webbrowser / download string via webclient etc
                "https://ipfs.io/ipfs/" + result.Id.Hash.ToString();

Let me know :)

Thanks @Jawadlord . I already solved this issue by using same Infura url.

Thanks again.