我尝试上传一个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())
}
}
}
您可能想看看这个博客。它详细说明了如何在Corda中实现附件的上传和下载。
它演示了使用两种不同方法下载附件的方法:
https://lankydan.dev/uploading-and-downloading-attachments-in-corda