0

I have tried to upload and send a file with the help of following link https://github.com/corda/corda/tree/release-M14

When I tried to used it in Cordaapp example it is showing many error. Is there any simple example to upload the file and attach? Is there any other simple example to refer the same?

1 Answers1

0

See the Blacklist example here.

You can upload an attachment to a node via HTTP:

<form action="/upload/attachment" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <input type="file" name="jar" class="form-control">
    </div>
    <br>
    <button type="submit" class="btn btn-default">Upload JAR</button>
</form>

Or you can upload an attachment using an RPC client:

val nodeAddress = parse(arg)
val rpcConnection = CordaRPCClient(nodeAddress).start("user1", "test")
val proxy = rpcConnection.proxy

val attachmentHash = uploadAttachment(proxy, JAR_PATH)

Then you add the attachment to a TransactionBuilder as follows:

val txBuilder = TransactionBuilder(notary)
    .addAttachment(attachmentHash)

It is up to you where you get the attachment hash. You may pass it as an argument to the flow, for example.

Joel
  • 22,762
  • 5
  • 26
  • 41
  • Thanks a lot. How to pass the attachment to other node and download the same from other node? –  Jun 21 '18 at 06:21
  • If an attachment is referenced by hash in a transaction that node A sends to node B, and node B has never seen the attachment corresponding to that hash, they will automatically request it from node A and cache it locally. – Joel Jun 21 '18 at 14:38
  • When you say `cache it locally` do you mean it is held in memory by node B until it finishes processing the transaction or it is permanently persisted in Node B's database? – Suhas Nov 17 '18 at 10:14
  • The attachment is persisted permanently in the node's database as a blob. – Joel Nov 19 '18 at 15:42