如何在Corda中获取附件元数据

如何在Corda中获取附件元数据,corda,Corda,文档使用以下API存储在Corda中: proxy.uploadAttachmentWithMetadata(pathname, uploader, filename) 以下API用于获取AttachmentId的列表 queryAttachments(Query: AttachmentQueryCriteria, sorting: AttachmentSort?) List<Atta chmentId> queryAttachments(查询:AttachmentQueryCr

文档使用以下API存储在Corda中:

proxy.uploadAttachmentWithMetadata(pathname, uploader, filename)
以下API用于获取AttachmentId的列表

queryAttachments(Query: AttachmentQueryCriteria, sorting: AttachmentSort?) List<Atta
chmentId>
queryAttachments(查询:AttachmentQueryCriteria,排序:AttachmentSort?)列表

有没有办法知道元数据,比如上传程序和文件名?上面的调用只返回id列表,不返回元数据。

您可以创建一个具有任何名称的zip文件并将其上载。 而且,在下载时,您可以提取zip文件并获取zip条目文件名或任何元数据

例如:

SecureHash hash = SecureHash.parse(org.apache.commons.lang3.StringUtils.substringAfter(reqPath,"attachments/"));
    InputStream attachment =  proxy.openAttachment(hash);//uploaded hash 
    String subPath = StringUtils.substringAfter(reqPath,"/").toLowerCase();
                resp.setContentType(MediaType.APPLICATION_OCTET_STREAM.toString());
     ZipInputStream zin = new ZipInputStream(attachment);
                    ZipEntry zipEntry  = zin.getNextEntry();
                    logger.info("file name:" +  zipEntry.getName());
                    resp.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="+ zipEntry.getName());
     byte[] bytes = IOUtils.toByteArray(zin);
    resp.getOutputStream().write(bytes);
基本上,corda只给你一个zip文件,文件名是散列。在你的Api端,你需要执行上面的步骤来获得文件名。 `