Command line example of adding file picture.jpg to Stream 'Photo'

+1 vote
Hi,

Could someone please help me with the steps (Commands) to add File to a Stream?

I have setup the chain, added nodes, published items in the streams. Now I am looking to add files directly to the Blockchain.

Rahul
asked Jan 3, 2017 by rahulkumargr

1 Answer

+2 votes

You would need to get the file contents in hexadecimal form, then pass it as a parameter to the publish command. If you are using bash on Linux, this is an example:

multichain-cli chain1 publish stream1 file1 `xxd -p README.txt | tr -d '\n'`

You need to substitute as appropriate:

  • chain1 for your blockchain name
  • stream1 for your stream name
  • file1 for the stream item key
  • README.txt for the file name

If you get an error from bash about the argument list being too long, you'll need to do this via the JSON-RPC API instead.

answered Jan 3, 2017 by MultiChain
Thanks for a prompt response.

Any idea how we can achieve this in Windows Environment?
Windows has an equivalent of the ` backtick operator, which lets you use a file contents as a command-line parameter - see here: http://stackoverflow.com/questions/2768608/batch-equivalent-of-bash-backticks

As for the conversion from binary to hexadecimal, you would probably want to do that in a separate stage - apparently there's a certutil command you can use:

http://stackoverflow.com/questions/4648118/converting-a-binary-file-to-hex-representation-using-batch-file
multichain-cli abc publish names file1 ‘for /f "usebackq tokens=*" %a in (fbireadme.hex) do @echo %a %I`

Tried the above on Windows machine. Unable to get it working.


Error:
error code:  -1
error message: publish "stream-identifier" "key" data-hex

Published Stream Item
I think the 'for' syntax is different, and you need to start with the 'for', then use the $ parameter within the final command line afterwards. Please take a look at some of the examples in the links posted above.
Thanks for all you help team.

for /f "usebackq tokens=*" %a in (readme.hex) do @echo %a | multichain-cli abc publish names Var1 %a

This is what finally worked for me.

Cheers,
Rahul
As for the Certutil, it does convert from ASCII to Hex, but the output file has line number, ASCII table and spaces.
I did exactly the command line you wrote and I have still a error code: -8

What could be the solution ?

Cheers,
Paul
...