【发布时间】:2018-06-28 16:37:14
【问题描述】:
我正在尝试在我的 Corda 应用程序中添加上传附件,但它无法正常工作,因为我在启动时遇到了错误。
[[FATAL] 未找到公共类型参数的注入源 javax.ws.rs.core.Response com.test.agreementnegotiation.api.AgreementNegotiationApi.uploadFile(java.lang.String,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) 在索引 0.;来源='资源方法{httpMethod=POST, 消费类型=[多部分/表单数据],生产类型=[], 暂停 = 假,暂停超时 = 0,暂停时间单位 = MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.test.agreementnegotiation.api.AgreementNegotiationApi, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@14ab26a]}, definitionMethod=public javax.ws.rs.core.Response com.test.agreementnegotiation.api.AgreementNegotiationApi.uploadFile(java.lang.String,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition), 参数=[参数[type=class java.lang.String, source=tags, defaultValue=], 参数 [type=class java.io.InputStream, source=file, defaultValue=null], 参数 [type=class org.glassfish.jersey.media.multipart.FormDataContentDisposition, 源=文件,默认值=空]],响应类型=类 javax.ws.rs.core.Response}, nameBindings=[]}']
下面是代码-
@Path("upload")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@DefaultValue("") @FormDataParam("tags") String tags,
@FormDataParam("file") InputStream file,
@FormDataParam("file") FormDataContentDisposition fileDisposition) {
String fileName = fileDisposition.getFileName();
saveFile(file, fileName);
String fileDetails = "File saved at " + UPLOAD_FOLDER + " " + fileName + " with tags "+ tags;
System.out.println(fileDetails);
return Response.ok(fileDetails).build();
}
private void saveFile(InputStream file, String name) {
try {
/* Change directory path */
java.nio.file.Path path = FileSystems.getDefault().getPath(UPLOAD_FOLDER + name);
/* Save InputStream as file */
Files.copy(file, path);
} catch (IOException ie) {
ie.printStackTrace();
}
}
我搜索错误,发现我们需要启用/resgiter MultiPartFeature。
我发现他们谈论更改 web.xml 或添加 AppCong 的任何链接,我不确定如何在 Corda 示例项目中完成。
Corda 团队请帮忙。
【问题讨论】: