本文介绍了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.

下面是代码-

@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.

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

无论我发现什么链接,他们都在谈论更改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附件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 06:13