Corda attachment sample code java


(Sameer Hameed) #1

HI,

Im trying to upload attachment using using corda java template. But not able to till now. Below is my code

SecureHash ourAttachmentHash = null;

        try {
            InputStream inputStream = new FileInputStream(new File("G:\\abc.zip"));
            String stringFile = new BufferedReader(new InputStreamReader(inputStream))
                    .lines().collect(Collectors.joining("\n"));
            ourAttachmentHash = SecureHash.sha256(stringFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            //TODO add handling
        }
        if (ourAttachmentHash != null) {
            txBuilder.addAttachment(ourAttachmentHash);
        }

`
Below while imitating flow im getting :
net.corda.core.contracts.AttachmentResolutionException: Attachment resolution failure for CDD1EFE257DC4EA5F1DE5B67D745D2FB24351DD48444FA056A4741B7B74FD181

Do we have any sample\example written code in java? Please assist.


(Roger Willis) #2

Hi - do you might asking this on stackoverflow - we’ve moved all Corda technical support there. Tag your question with #corda.

Cheers!