Corda附件上传
Corda attachment upload
我正在尝试在我的 Corda 应用程序中添加上传附件,但它不起作用,因为我在启动时遇到以下错误。
[[FATAL] No injection source found for a parameter of type public
javax.ws.rs.core.Response
com.test.agreementnegotiation.api.AgreementNegotiationApi.uploadFile(java.lang.String,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition)
at index 0.; source='ResourceMethod{httpMethod=POST,
consumedTypes=[multipart/form-data], producedTypes=[],
suspended=false, suspendTimeout=0, suspendTimeoutUnit=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),
parameters=[Parameter [type=class java.lang.String, source=tags,
defaultValue=], Parameter [type=class java.io.InputStream,
source=file, defaultValue=null], Parameter [type=class
org.glassfish.jersey.media.multipart.FormDataContentDisposition,
source=file, defaultValue=null]], responseType=class
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();
}
}
我搜索错误,发现我们需要 enable/resgiter MultiPartFeature。
随便 link 我发现他们谈论更改 web.xml 或添加 AppCong,我不确定如何在 Corda 示例项目中完成。
Corda 团队请帮忙。
内置节点网络服务器有一个用于上传附件的默认端点,/upload/*
。此端点开箱即用,无需添加到您的 API 中。您通过使用编码类型 multipart/form-data
.
向此端点发出 POST 请求来上传附件
例如:
<form action="/upload/attachment" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="jar" class="form-control">
</div>
<br>
<button type="submit" class="btn btn-default">Upload blacklist</button>
</form>
您不能提供自己的附加端点来上传附件。
如果您编写自己的节点网络服务器(例如 Spring webserver),则没有任何限制。
已弃用的网络服务器端点 /upload/attachment
在 corda V4 中不再工作
我正在尝试在我的 Corda 应用程序中添加上传附件,但它不起作用,因为我在启动时遇到以下错误。
[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response com.test.agreementnegotiation.api.AgreementNegotiationApi.uploadFile(java.lang.String,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) at index 0.; source='ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[], suspended=false, suspendTimeout=0, suspendTimeoutUnit=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), parameters=[Parameter [type=class java.lang.String, source=tags, defaultValue=], Parameter [type=class java.io.InputStream, source=file, defaultValue=null], Parameter [type=class org.glassfish.jersey.media.multipart.FormDataContentDisposition, source=file, defaultValue=null]], responseType=class 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();
}
}
我搜索错误,发现我们需要 enable/resgiter MultiPartFeature。
随便 link 我发现他们谈论更改 web.xml 或添加 AppCong,我不确定如何在 Corda 示例项目中完成。
Corda 团队请帮忙。
内置节点网络服务器有一个用于上传附件的默认端点,/upload/*
。此端点开箱即用,无需添加到您的 API 中。您通过使用编码类型 multipart/form-data
.
例如:
<form action="/upload/attachment" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="jar" class="form-control">
</div>
<br>
<button type="submit" class="btn btn-default">Upload blacklist</button>
</form>
您不能提供自己的附加端点来上传附件。
如果您编写自己的节点网络服务器(例如 Spring webserver),则没有任何限制。
已弃用的网络服务器端点 /upload/attachment
在 corda V4 中不再工作