This Cordapp shows how to upload and download an attachment via flow. In this Cordapp, there are two parties:
- Seller: sends an invoice (with attachment) to Buyer
- Buyer: receive the the invoice and be able to download the attached zip file to their local machine
There is one state InvoiceState and two flows sendAttachment and downloadAttachment. The flow logic is the following:
-
sendAttachment: send and sync the attachment between parties- Uploading attachment from local
- Attaching the accachmentID to the transaction
- Storing the attached file into attachment service at the counterparty's node (Automatically check if it already exists or not. If it does, do nothing; if not, download the attached file from the conterparty.)
-
downloadAttchment: save the attachment file from node's serviceHub to local- signing the attachment service in the node to download the file via attachmentID
Deploy and run the nodes by:
Java
./gradlew workflows-java:deployNodes
.workflows-java/build/nodes/runnodes
or Kotlin
./gradlew workflows-kotlin:deployNodes
.workflows-kotlin/build/nodes/runnodes
if you have any questions during setup, please go to https://docs.corda.net/getting-set-up.html for detailed setup instructions.
Once all three nodes are started up, in Seller's node shell, run:
flow start SendAttachment receiver: Buyer
After this call, we already finished
- uploading a zip file to Seller's node
- sending the zip file to Buyer's node
Now, lets move to Buyer's node shell, and run:
flow start DownloadAttachment sender: Seller, path: file.zip
This command is telling the node to retrieve attachment from the transaction that is sent by Sellerand download it as file.zip at the node root direction (
- This uploaded file is hardcoded into the flow.
- The transaction retrieving is also hardcoded to retrieve the first state that being stored in the vault.

