# Geting the hash sha-256 of a file for upload perpuses

**URL:** <https://discourse.elm-lang.org/t/geting-the-hash-sha-256-of-a-file-for-upload-perpuses/4486>\
**Category:** Learn\
**Created:** [October 15, 2019, 9:19am UTC](https://discourse.elm-lang.org/t/geting-the-hash-sha-256-of-a-file-for-upload-perpuses/4486 "2019-10-15T09:19:36Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![Nikolis\_Galerakis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/nikolis_galerakis/32/2479_2.png) [@Nikolis\_Galerakis](https://discourse.elm-lang.org/u/Nikolis_Galerakis)\
**Post date:** [October 19, 2019, 12:00pm UTC](https://discourse.elm-lang.org/t/geting-the-hash-sha-256-of-a-file-for-upload-perpuses/4486/19 "2019-10-19T12:00:00Z")

</div>

What did the trick for me was:

1. Define an hiden input in elm with type file(So you are not able to use it as a user)
2. I have defined an onchange function also in the elm side that will allo me to know which file was selected if any
3. Registering a port function that when invoked trigers the click behaviour of the hidden input
4. Register onchange callback on the javascript side on the same input object defined in the elm side
5. when the file changes I calculate in the javascript side the hash of the file using the crypto-js/sha256
6. using a port I send back the value calculater in the javascript side.

---

_[View the full topic](https://discourse.elm-lang.org/t/geting-the-hash-sha-256-of-a-file-for-upload-perpuses/4486)._
