There are several nuances with binary data types. In this article we are going to cover different ways how to set the binary node and how  and what value it will be set with.
Assume we are using the following data model:


module test {
    namespace "http://netconfcentral.org/ns/test";
    prefix "t";

    ...

    leaf binary.1 {
       type binary;
    }

    ...

}


1) When you use your XML or JSON to send the edit to the server the binary value should be already base64 encoded.

The server will not encode the value for you in this case.

 

Example:

Send <edit-config>


<edit-config>
    <config>
        <binary.1 xmlns="http://netconfcentral.org/ns/test">1234</binary.1>
    </config>
</edit-config> 


The server will use the '1234' value as already base64 encoded value and will store the '1234' value into the datastore as the value for the 'binary.1' node. 

So, in this case you need to send the following XML with base64 value:

 

> echo -n '1234' | base64
MTIzNA==

 <edit-config>
    <config>
        <binary.1 xmlns="http://netconfcentral.org/ns/test">MTIzNA==</binary.1>
    </config>
</edit-config>


 

2) When you use yangcli-pro for the same operation, the client tool will encode the value for you.

 

Example:

 

yangcli > create /binary.1 value='1234'
yangcli> get-config

..
<binary.1 xmlns="http://netconfcentral.org/ns/test">MTIzNA==</binary.1>
..