Corda附件上传

时间:2018-06-28 16:37:15

标签: java jersey corda

我正在尝试在我的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。 source ='ResourceMethod {httpMethod = POST,   enabledTypes = [多部分/表单数据],producedTypes = [],   暂停=否,暂停时间= 0,暂停时间单位= MILLISECONDS,   invocable = Invocable {handler = ClassBasedMethodHandler {handlerClass = class   com.test.agreementnegotiation.api.AgreementNegotiationApi,   handlerConstructors = [org.glassfish.jersey.server.model.HandlerConstructor@14ab26a]},   definitionMethod =公共javax.ws.rs.core.Response   com.test.agreementnegotiation.api.AgreementNegotiationApi.uploadFile(java.lang.String,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition),   parameter = [Parameter [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,   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();
        }
    }

我搜索了错误,发现我们需要启用/重新设置MultiPartFeature。

https://www.google.co.uk/search?q=No+injection+source+found+for+a+parameter+site:stackoverflow.com&sa=X&ved=0ahUKEwjn5ePy5PbbAhWMOxQKHQHXAUkQrQIIUCgEMAI&biw=1280&bih=958

无论我发现什么链接,他们都在谈论更改web.xml或添加AppCong,但我不确定在Corda示例项目中如何完成。

Corda团队请帮忙。

2 个答案:

答案 0 :(得分:0)

内置节点Web服务器具有用于上传附件的默认端点/upload/*。此端点是现成可用的,不需要在您的API中添加。您可以通过向该终结点发出POST请求,并使用编码类型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>

您不能提供自己的其他端点来上传附件。

如果您编写自己的节点Web服务器(例如Spring webserver),则没有任何限制。

答案 1 :(得分:0)

已弃用的Web服务器List <IdentityUser> does not contain a definition for GetAwaiter and no accessible method GetAwaiter accepting a first argument of type List<IdentityUser> could be found 的端点在Corda V4中不再起作用