Как скачать файл jar в corda при вводе значения хеша? - PullRequest
0 голосов
/ 02 июля 2018

Я попытался загрузить ZIP-файл и получил хэш. Теперь я позвонил в API. В этом я даю хэш для загрузки файла. Но я не могу скачать файл.

@PUT
@Path("download_file")
fun createIOU(
        @QueryParam("sechash") sechash: String
): Response {

    val SecuHash = SecureHash.parse(sechash)
    return try {
        val attachmentJr = downloadAttachment(rpcOps, SecuHash)
        println("jar      :"+attachmentJr)
        Response.status(CREATED).entity("Transaction id ${attachmentJr} committed to ledger.\n").build()
    } catch (ex: Throwable) {
        logger.error(ex.message, ex)
        Response.status(BAD_REQUEST).entity(ex.message!!).build()
    }
}

private fun downloadAttachment(proxy: CordaRPCOps, attachmentHash: SecureHash) {
    //Get the attachmentJar from node for attachmentHash.
    val attachmentJar = proxy.openAttachment(attachmentHash)
    //Read the content of Jar to get file name and data.
    var file_name_data: Pair<String, ByteArray>? = null
    JarInputStream(attachmentJar).use { jar ->
        while (true) {
            val nje = jar.nextEntry ?: break
            if (nje.isDirectory) {
                continue
            }
            file_name_data = Pair(nje.name, jar.readBytes())

        }
    }
}
...