Corda附件上传 [英] Corda attachment upload

查看:138
本文介绍了Corda附件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Corda应用程序中添加上传附件,但由于我在启动时遇到错误而无法正常工作.

I'm trying to add upload attachment in my Corda application but it's not working as I'm getting below error at start up itself.

[[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 = [multipart/form-data],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 = []}']

[[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();
        }
    }

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

I searched on error and found that we need to enable/resgiter MultiPartFeature.

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

Whatever link I found they talk about changing web.xml or adding AppCong and I'm Not sure how it can be done in Corda sample project.

Corda团队请帮忙.

Corda team please help.

推荐答案

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

The built-in node webserver has a default endpoint for uploading attachments, /upload/*. This endpoint is available out-of-the-box and does not need to be added in your API. You upload an attachment by making a POST request to this endpoint with the encoding type 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>

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

You cannot provide your own additional endpoints for uploading attachments.

如果您编写自己的节点网络服务器(例如 Spring网络服务器),则有没有限制.

If you write your own node webserver (e.g. a Spring webserver), then there are no limitations.

这篇关于Corda附件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆