ipfs / kubo

An IPFS implementation in Go
https://docs.ipfs.tech/how-to/command-line-quick-start/
Other
15.89k stars 2.97k forks source link

Allow adding directories via curl #3153

Open knupfer opened 7 years ago

knupfer commented 7 years ago

Version/Platform/Processor information (from ipfs version --all):

go-ipfs version: 0.4.3-dev-b5fbc01 Repo version: 4 System version: amd64/linux Golang version: go1.6.2

Type (bug, feature, meta, test failure, question):

feature

Area (api, commands, daemon, fuse, etc):

api

Priority (from P0: functioning, to P4: operations on fire):

Description:

Provide a command, which takes a tarball, untars it and adds the untared content to ipfs. This is useful to be able to add directories to ipfs via curl.

knupfer commented 7 years ago

Note: I'm aware of ipfs tar add, but it results in a non browsable path which can be only read with ipfs cat which isn't even part of the api under port 8080

jbenet commented 7 years ago

You should be able to do this already. It's how the add command works in general. it may involve multipart. Maybe inspect the api call that go-ipfs does when an ipfs add -r <dir> command happens. or look at https://github.com/ipfs/js-ipfs-api.

I tried looking in docs.ipfs.apiary.io/#reference/add but i'm getting lost / didnt find a clear example with a directory + many files.

jbenet commented 7 years ago

you may have to untar yourself, then pipe it into an ipfs add (multipart, i think) stream

ghost commented 7 years ago

~~I've successfully piped docker image tarballs into ipfs tar add in the past~~

ghost commented 7 years ago

eh sorry disregard my other comment.

Another idea: the hash of an empty unixfs directory is currently QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn (it'll change with IPLD), you can use that to build your directory, iterating over all children, patching them into the directory.

What @jbenet said about untar'ing as multipart into /api/v0/add might be better.

knupfer commented 7 years ago

I'll give it a try, didn't think about that.

whyrusleeping commented 7 years ago

It would be pretty nice to have an 'inverse' of ipfs get --archive. @knupfer what would an ideal API look like for you here?

knupfer commented 7 years ago

Perhaps ipfs add --archive ? I like symmetries a lot.

whyrusleeping commented 7 years ago

@knupfer I really like that. ipfs add --archive could take a tar stream as input data.