ipfs-shipyard / net-ipfs-http-client

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

Add files doesn't show up in IPFS local node #14

Closed zipgenius closed 1 year ago

zipgenius commented 1 year ago

I'm new to IPFS development and maybe I'm missing something but I can't make to list files in IPFS client list.

I'm using the following code: string pFile = @"C:\Users\matte\Desktop\dump_languagefiles.pdf"; var ipfs = new IpfsClient(); AddFileOptions options = new AddFileOptions(); options. Pin = true; options.OnlyHash = false; options. Wrap = false; IFileSystemNode ipfsNode = await ipfs.FileSystem.AddFileAsync(pFile, options, default);

But nothing appears here: image

Derrick- commented 1 year ago

From what I can see, the FileSystemApi implementation is incomplete and for the most part does not uses the /files/ commands.

AddFileAsync only adds the file to the node, and returns the FileSystemNode of the file (or directory). You can see that code here, it uses the /add command and not the MFS subsystem api: /files/

It does not actually add it to the MFS files system of the node which might be implemented by a subsequent /files/cp command to hang the file or directory at a specified path.

I would be interested in working on FileSystemApi or collaborating with anyone else interested in getting this working as expected

Derrick- commented 1 year ago

On a second look, FileSystemApi does not support /api/files at all

It has API call to /file/ls which is deprecated which led me to believe that this class was supposed to be talking to the /files api's, it's actually more of a utility class.

The entire MFS command set should be implemented. I suspect that MFS was not yet released at the time of FileSystemApi creation.

A new API interface and class such as MfsApi should probably be implemented. This work would have to be integrated in net-ipfs-core CoreApi as well

zipgenius commented 1 year ago

This is my workaround for now, assuming pFile is a StorageFile object:

IpfsClient ipfs = new IpfsClient(); using (Stream fStream = await pFile.OpenStreamForReadAsync()) { var response = await ipfs.UploadAsync("add", default, fStream, Path.GetFileName(pFile.Name), new string[] { "to-files", "/" }); dynamic data = JsonConvert.DeserializeObject(response); string jHash = data.Hash; string jName = data.Name; } Now I can see the file where it is expected to be.

Maverick1983 commented 1 year ago

Sorry, I don't understand if code it's working or not. Can I help?

Derrick- commented 1 year ago

await ipfs.Mfs.WriteAsync now provides the desired functionality

See: https://github.com/ipfs-shipyard/net-ipfs-http-client/pull/16/files#diff-87d5ab27d9c93d3429cfb2fcdc5fcc7005848241ebde52b6474aaec82f493539R169

Close issue @Arlodotexe ?