File Type value from /files/ls command

Hello,
I am using files/write to upload a file to MFS, using http api:

http headers:
Content-Disposition: file; name=“file”;
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

url:
http://127.0.0.1:5001/api/v0/files/write?e=true&arg=/invalid.txt

when I use this url http://127.0.0.1:5001/api/v0/files/ls?arg=/
it returns:
{“Entries”:[{“Name”:“invalid.txt”,“Type”:0,“Size”:0,“Hash”:""}]}

when I use this url http://127.0.0.1:5001/api/v0/files/ls?arg=/invalid.txt
it returns:
{“Entries”:[{“Name”:“invalid.txt”,“Type”:1,“Size”:0,“Hash”:""}]}

I am curious, what is the first output with ‘Type: 0’ ?

I thought ‘/files/ls path’ should return a list of files and sub folders under the ‘path’ right ? why invalid.txt is returned with two different type values ?

thanks !

what is the first output with ‘Type: 0’ ?

The Type field is the type of object — e.g. a directory, a file, a symlink, etc. You can see a list here, where the protobuf format for UnixFS is defined: https://github.com/ipfs/go-ipfs/blob/master/unixfs/pb/unixfs.proto (unfortunately, UnixFS and these values aren’t formally documented anywhere).

why invalid.txt is returned with two different type values?

IPFS generally tries to always return the exact same format of data for a given command, regardless of the arguments. When you call files/ls without the l option, it only includes file names. All the other fields get left to their “unset” values (0 for numbers, “” for strings). If you add the l option, you should see all those fields filled in:

http://localhost:5001/api/v0/files/ls?arg=/&l
# or
http://localhost:5001/api/v0/files/ls?arg=/&l=true

the strange things are:

  1. I got 0 or 1 not 1 (directory) or 2(file) according to the spec
  2. I got both 0 and 1 for the file.

Ah, sorry @canal, I got this wrong (as have, apparently, a whole bunch of other people). The UnixFS types (that you get with /ls) and MFS types (that you get with /files/ls are different). MFS uses 0 for files and 1 for directories.

thanks for confirming, I got a bit confused also :slight_smile: