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
You'll want to take a quick look at InvoiceState.java
public InvoiceState(String invoiceAttachmentID, List<AbstractParty> participants) {
this.invoiceAttachmentID = invoiceAttachmentID;
this.participants = participants;
}
There are 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
Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)
./gradlew clean deployNodes
Then type: (to run the nodes)
./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 Seller
and 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.