Hash function in $binary object

Describe the problem/error/question

I just encoutered that the hash() function is not available in den $binary object but can be called via the $input object. Thus:
“Hash”: “{{ $input.item.binary.data.data.hash(‘sha256’) }}” - Works
but
”Hash” : “{{ $binary.data.data.hash(‘sha265) }}” - does not work / hash function is unknown in the object.

Since the hash function is must likely be called on binary data it would be an improvment to include it in the $binary object.

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: Version 1.123.13
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): -
  • Running n8n via (Docker, npm, n8n cloud, desktop app): -
  • Operating system: Linux
1 Like

Hey @micha99 Welcome to the n8n community!

The core issue you’re encountering is that the hash() function is accessible when using the $input object but not available in the $binary object. Specifically:

  • When you do {{ $input.item.binary.data.data.hash('sha256') }}, it works because you’re calling hash() on a string value within the binary data.
  • When you try {{ $binary.data.data.hash('sha256') }}, it doesn’t work because $binary itself doesn’t have the hash() function; it’s just an object representing the binary data, not a string helper.

the hash() helper is only available for string values, and $binary is a shortcut for the binary data object, not a string. Therefore, calling hash() directly on $binary does not work.

Proposed improvement:
It would be beneficial if the $binary object included the hash() function or similar string helpers, especially since hashing binary data is a common use case. This would make the workflow more straightforward, avoiding the need to explicitly navigate to the string inside the binary object each time.

Your workflow example:

  • Works: {{ $input.item.binary.data.data.hash('sha256') }}
  • Doesn’t work: {{ $binary.data.data.hash('sha256') }}

Let me know if this helps.

Your right / I use the $input object already (took me some time to figure this out…), but as you pointed out as well it would much cleaner to use the $binary object :slight_smile:

1 Like

Yeah it would be really nice if they implement that! Like do you need any help with that?

No, I’m fine - thanks for the lighting-fast reply :wink:

1 Like

Like if it helped you in anything mark as a solution, thanks!