LIferay上的AJAX文件上传:无法匹配参数

时间:2015-05-22 20:20:29

标签: liferay liferay-aui

我正在尝试编写一个Liferay portlet,通过AJAX将文件上传发送到JSONWS端点,但我在日志文件中不断收到以下错误:

DEBUG [http-bio-8080-exec-70][JSONWebServiceActionsManagerImpl:121] Request JSON web service action with path /document/upload-file and method POST for //document-portlet
DEBUG [http-bio-8080-exec-70][JSONWebServiceActionsManagerImpl:455] Found 1 JSON web service actions with path /document-portlet/document/upload-file in for //document-portlet
DEBUG [http-bio-8080-exec-70][JSONWebServiceActionsManagerImpl:501] Unable to match parameters to a JSON web service action with path /document-portlet/document/upload-file for //document-portlet
ERROR [http-bio-8080-exec-70][JSONWebServiceServiceAction:97] No JSON web service action associated with path /document/upload-file and method POST for //document-portlet

在几个教程之后,我的JSONWS实现如下所示:

class DocumentServiceImpl extends DocumentServiceBaseImpl {

    @JSONWebService(method="POST")
    public String uploadFile(File content) {
         // ...
    }
}

这是我的客户端代码:

<aui:form name="files" enctype="multipart/form-data">
    <aui:input type="file" name="content" label="File" />
    <aui:button type="submit" name="btnUploadFile" value="Upload file" />
</aui:form>

<script>
AUI().use(
    'aui-io-request',
    function(A) {
        var btnUploadFile = A.one("#<portlet:namespace />btnUploadFile");

        btnUploadFile.on("click",
            function(event) {
                event.preventDefault();
                var myForm = A.one("#<portlet:namespace/>files");
                var ajaxURL = "http://localhost:8080/api/jsonws/document-portlet.document/upload-file";

                var configs = {
                    method : 'POST',
                    form : {
                        id : myForm,
                        upload : true
                    },
                    sync : true,
                    on : {
                        complete : function() {
                            // ...
                        }
                    }
                };

                A.io.request(ajaxURL, configs);
            }
        )
    }
);
</script>

在我看来,Liferay发现了uploadFile方法,但它无法将请求的签名与方法的参数相匹配。如何匹配multipart / form-data请求的参数?或者我是以错误的方式解决这个问题?

0 个答案:

没有答案