iamatulK
iamatulK

Reputation: 105

Unable to download attachment in corda

Trying to download an attachment from a corda node using rpc client:

@GetMapping("/download/{hash}")
fun download(@PathVariable("hash") hash : String) : ResponseEntity<Any> {
    return try {
        val input = SecureHash.parse(hash)
        val file = ZipInputStream(rpc.proxy.openAttachment(input))
        ResponseEntity.status(HttpStatus.OK).body(file)
    }catch (e: Exception) {
        ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.message)
    }
}

The out put from above code is:

{
   nextEntry: {
         name: "11.c",
         crc: 2689263033,
         size: 675,
         method: 8,
         extra: "VVQJAAN22XNb2EuCW3V4CwABBOgDAAAE6AMAAA==",
         comment: null,
         time: 1534318966000,
         lastAccessTime: { },
         creationTime: null,
         compressedSize: 332,
         directory: false,
         lastModifiedTime: { }
    }

}

But I am not able to find any downloaded zip, if it is downloaded i don`t know in which directory , Inside zip there is a pdf file I want to download it locally and open it.

Upvotes: 0

Views: 220

Answers (1)

Joel
Joel

Reputation: 23160

openAttachment returns an input stream, rather than causing the attachment to be downloaded to somewhere on your node.

You need to take this input stream and save it as a JAR file, which you can then unzip to access the PDF.

Upvotes: 1

Related Questions