Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

IPFS /api/v0/add #4

Closed
lightninglu10 opened this issue Dec 6, 2017 · 6 comments · Fixed by #27
Closed

IPFS /api/v0/add #4

lightninglu10 opened this issue Dec 6, 2017 · 6 comments · Fixed by #27

Comments

@lightninglu10
Copy link

Hey guys, the docs here are really confusing: https://ipfs.io/docs/api/#apiv0add

How is this endpoint used? Currently we're just posting form data like this:

const formData = new FormData();
formData.append('ipfsfile', new Buffer(ipfsFile.buffer));
return fetch(ipfsUrl, {method: 'post', body: formData})

in Node.js. We have everything in the formData with the key 'ipfsfile' -- is this a problem? Will files be overwritten and then hashes be unusable?

We're running into an issue where our pinned content / hashes disappear.

@Mr0grog
Copy link
Contributor

Mr0grog commented May 23, 2018

I know this is super old, but in case you never solved it or anyone else is looking at this:

What you post here needs to have a filename, which is a third argument with the FormData API. I think you also need to make sure to set the Content-Type. In a browser, you’d do that with a Blob like so:

const formData = new FormData();
formData.append('file', new Blob([fileContent], {type : 'application/octet-stream'}), 'filename.txt');
fetch('http://localhost:5001/api/v0/add', {method: 'POST', body: formData, mode: 'cors' });

Obviously you probably don’t need mode: 'cors' in Node.js. Depending on what port of FormData you’re using, there will be different ways to set the content type.


All that said: yeah, stuff like the above needs to be in the docs generated here. This is still an issue.

@parkan
Copy link

parkan commented Feb 11, 2019

@hsanjuan coming to this repo because I was unable to provide a coherent answer here: ipfs/kubo#5984 and I see others are confused as well

the docs say:

arg [file]: The path to a file to be added to ipfs. Required: yes.

and further down:

Argument “path” is of file type. This endpoint expects a file in the body of the request as ‘multipart/form-data’.

neither of which is correct -- posting ?arg=some_path results in File arguiment 'path' is required and the latter specifies the wrong parameter name for uploading the file body (path instead of file)

it is also unclear whether it's possible to use this approach with filestore (nocopy=true) because the path argument isn't accepted

I can PR to fix this to reflect the file=@.. approach but I want to make sure this repo is not considered deprecated

@hsanjuan
Copy link
Member

hey @parkan , the problem is that IPFS CLI and HTTP API share the same code and documentation is autogenerated from help messages which are usually valid for both (which works well enough in 99% of cases).

I'm happy to take the PR to be clearer about file=@. This repo is not deprecated.

@parkan
Copy link

parkan commented Feb 12, 2019

got it! will fix once I figure out the right way to use this with filestore (ipfs/kubo#4558)

@hsanjuan
Copy link
Member

hsanjuan commented Mar 9, 2020

@parkan shall we keep this open?

Also #25 .

@parkan
Copy link

parkan commented Mar 9, 2020

@hsanjuan I haven't really worked with filestore in a while so I'm not sure I have the right context for this anymore, sorry

hsanjuan added a commit that referenced this issue Apr 6, 2020
* Document how to send the multiparts for /add
* Bring markdown geneartion in line with ipfs-docs-v2
* Ignore client-side options
* Set curl -X POST
* Do not list args of type File in arguments
* Improve some formatting

This still leaves things at 0.4.22 so that then we can get a clean
diff of changes for 0.4.23 and eventually for 0.5.0.

Fixes #25
Fixes #4
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants