# Get ipfs hash of file from code

**URL:** <https://discuss.ipfs.tech/t/get-ipfs-hash-of-file-from-code/3217>\
**Category:** Help\
**Tags:** go-ipfs\
**Created:** [June 18, 2018, 7:03am UTC](https://discuss.ipfs.tech/t/get-ipfs-hash-of-file-from-code/3217 "2018-06-18T07:03:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pop](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@pop](https://discuss.ipfs.tech/u/pop)\
**Post date:** [June 18, 2018, 7:03am UTC](https://discuss.ipfs.tech/t/get-ipfs-hash-of-file-from-code/3217/1 "2018-06-18T07:03:13Z")

</div>

Hello. I’m writing small application that uses ipfs internally. I am launching ipfs node from go code and everything works great. But recently needed to get ipfs hash of file and it appeared to be a problem. I found than calling add command with only hash option might help me, but unfortunately it doesn’t return ipfs hash directly, but prints it directly to stdout using fmt.Fprintf. Maybe somebody knows better way to do it rather than rewriting “add” command in my project or modifying ipfs codebase?

---

<div class="post-metadata">

**Author:** ![stebalien](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/stebalien/32/156_2.png) [@stebalien](https://discuss.ipfs.tech/u/stebalien)\
**Post date:** [June 19, 2018, 7:12pm UTC](https://discuss.ipfs.tech/t/get-ipfs-hash-of-file-from-code/3217/2 "2018-06-19T19:12:34Z")

</div>

From go, one generally uses the CoreAPI. It’s currently a bit in-flux/in-progress at the moment, but you can construct a `CoreAPI` node by calling `coreapi.NewCoreAPI(myIpfsNode)`. You can then call myCoreAPI.Unixfs().Add(ctx, someReader)`.

You can avoid actually _adding_ the file to the local datastore by constructing a new `IpfsNode` with the `NilRepo` option set to true. See:

> <https://github.com/ipfs/go-ipfs/blob/2a9de81e64d563c5bd86b058aa251cbe94faf86f/core/commands/add.go#L237-L248>
