# How to POST via curl

**URL:** <https://discuss.ipfs.tech/t/how-to-post-via-curl/1163>\
**Category:** Uncategorized\
**Created:** [September 27, 2017, 3:48pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163 "2017-09-27T15:48:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbluth](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/cbluth/32/151_2.png) [@cbluth](https://discuss.ipfs.tech/u/cbluth)\
**Post date:** [September 27, 2017, 3:48pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/1 "2017-09-27T15:48:22Z")

</div>

I am looking for the curl equivalent of `ipfs add filename.ext -w` for curl.  
I want to `curl -v -X POST --binary-data @filename http://localhost:8080/`, but it doesnt retain the filename.

Anyone know how to do it?

---

<div class="post-metadata">

**Author:** ![VictorBjelkholm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/victorbjelkholm/32/10_2.png) [@VictorBjelkholm](https://discuss.ipfs.tech/u/VictorBjelkholm)\
**Post date:** [September 27, 2017, 5:54pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/2 "2017-09-27T17:54:39Z")

</div>

Handy general tip when you want to figure out what the go-ipfs cli command would look like for cURL, run tcpdump and grep for POST:

```auto
sudo tcpdump -A port 5001 -i any | grep POST

```

This will print out all the POST request URLs that you’ll make to port 5001 on local interfaces. We can then see:

```auto
tcpdump: data link type PKTAP
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type PKTAP (Apple DLT_PKTAP), capture size 262144 bytes
,.>.,.>.POST /api/v0/add?encoding=json&progress=true&stream-channels=true&w=true HTTP/1.1
,.>.,.>.POST /api/v0/add?encoding=json&progress=true&stream-channels=true&w=true HTTP/1.1

```

So what you have to add in the end, is `?w=true` to your request URL.

---

<div class="post-metadata">

**Author:** ![VictorBjelkholm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/victorbjelkholm/32/10_2.png) [@VictorBjelkholm](https://discuss.ipfs.tech/u/VictorBjelkholm)\
**Post date:** [September 27, 2017, 5:55pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/3 "2017-09-27T17:55:30Z")

</div>

I realize now that you’re dealing with the writable gateway rather than the API, so my answer is not applicable. But I’ll leave it there, in case it’s useful for someone else in the future.

Regarding wrapping a file when adding via the gateway, I’m unsure of if it’s possible…

---

<div class="post-metadata">

**Author:** ![cbluth](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/cbluth/32/151_2.png) [@cbluth](https://discuss.ipfs.tech/u/cbluth)\
**Post date:** [September 27, 2017, 6:32pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/4 "2017-09-27T18:32:27Z")

</div>

> [@VictorBjelkholm](#):
>
> Regarding wrapping a file when adding via the gateway, I’m unsure of if it’s possible…

Bummer…  
I thought I saw that was an option at one point.

---

<div class="post-metadata">

**Author:** ![VictorBjelkholm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/victorbjelkholm/32/10_2.png) [@VictorBjelkholm](https://discuss.ipfs.tech/u/VictorBjelkholm)\
**Post date:** [September 27, 2017, 6:45pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/5 "2017-09-27T18:45:57Z")

</div>

Good news! Your thought was correct and it is possible to add files to a empty directory.

First, `QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn` is the hash of a empty directory (see the structure with `ipfs object get QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn`), and with that, we can create new DAG that includes our newly created file.

A example:

```auto
curl -v -X PUT --data 'hello world' http://localhost:8081/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/hello

```

This would use the existing empty directory, create a file called `hello` and add the content `hello world`.

The resulting hash can be found in the `Ipfs-Hash` header and the full path can be found in the `Location` header.

---

<div class="post-metadata">

**Author:** ![cbluth](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/cbluth/32/151_2.png) [@cbluth](https://discuss.ipfs.tech/u/cbluth)\
**Post date:** [September 27, 2017, 7:14pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/6 "2017-09-27T19:14:32Z")

</div>

Yes, that’s exactly it.  
Thanks!

---

<div class="post-metadata">

**Author:** ![cbluth](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/cbluth/32/151_2.png) [@cbluth](https://discuss.ipfs.tech/u/cbluth)\
**Post date:** [September 27, 2017, 7:23pm UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/7 "2017-09-27T19:23:52Z")

</div>

So, as it turns out, you can use any DAG, the difference is between a `POST` and a `PUT`.

---

<div class="post-metadata">

**Author:** ![soul](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@soul](https://discuss.ipfs.tech/u/soul)\
**Post date:** [September 10, 2018, 9:28am UTC](https://discuss.ipfs.tech/t/how-to-post-via-curl/1163/8 "2018-09-10T09:28:22Z")

</div>

curl -F “file=@ipfs” “[http://localhost:5001/api/v0/add?recursive=true](http://localhost:5001/api/v0/add?recursive=true)” this command not work and ipfs is a folder, anyone know why?
