无法使用MobileFoundation Adapter上传文件

时间:2017-12-05 07:42:21

标签: ibm-mobilefirst

我们创建了一个Java Adapter,它调用API来通过MobileFoundation上传文件。但是,当应用程序调用适配器时,它将导致服务器错误,并且将无法工作。 另外,我创建了一个JavaScript Adapter,但是发生了同样的错误。 请告诉我如何解决。

创建的适配器如下。

@POST
@Path("/uploadimage")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@OAuthSecurity(enabled=false)
public void postFileUpload(@Context HttpServletResponse response,
        @FormParam("image_type") @DefaultValue("") String image_type,
        @Encoded @FormParam("file") File file
        )
        throws IOException, IllegalStateException, SAXException {

(由于在到达逻辑内部之前是错误,因此省略了方法内容。)

错误如下。

[12/5/17 6:09:38:687 UTC] 0000af3f SystemErr R java.lang.RuntimeException: Invalid URL encoding: not a valid digit (radix 16): 14
[12/5/17 6:09:38:688 UTC] 0000af3f SystemErr R       at org.apache.cxf.common.util.UrlUtils.digit16(UrlUtils.java:114)
[12/5/17 6:09:38:688 UTC] 0000af3f SystemErr R       at org.apache.cxf.common.util.UrlUtils.urlDecode(UrlUtils.java:94)
[12/5/17 6:09:38:689 UTC] 0000af3f SystemErr R       at org.apache.cxf.common.util.UrlUtils.urlDecode(UrlUtils.java:66)
[12/5/17 6:09:38:689 UTC] 0000af3f SystemErr R       at org.apache.cxf.common.util.UrlUtils.urlDecode(UrlUtils.java:121)
[12/5/17 6:09:38:689 UTC] 0000af3f SystemErr R       at org.apache.cxf.jaxrs.utils.HttpUtils.urlDecode(HttpUtils.java:94)
[12/5/17 6:09:38:689 UTC] 0000af3f SystemErr R       at org.apache.cxf.jaxrs.utils.FormUtils.populateMapFromMultipart(FormUtils.java:223)
[12/5/17 6:09:38:689 UTC] 0000af3f SystemErr R       at org.apache.cxf.jaxrs.utils.JAXRSUtils.processFormParam(JAXRSUtils.java:956)
[12/5/17 6:09:38:691 UTC] 0000af3f SystemErr R       at org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:877)
[12/5/17 6:09:38:692 UTC] 0000af3f SystemErr R       at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:837)
[12/5/17 6:09:38:692 UTC] 0000af3f SystemErr R       at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:787)
......

创建的Dummy JavaScript Adapter如下所示。

function postImage() {
var input = {
        method : 'post',
        returnedContentType : 'json',
        path : "test/"
    };

    return MFP.Server.invokeHttp(input);}

请求如下。

POST https://*****.mybluemix.net/mfp/api/adapters/JsAdapter/postImage

POST data:
--4ds9bnG-WijS3-W773egmV2-qxb8LBZeUfEr
Content-Disposition: form-data; name="timestamp"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

2017-11-20 14:55:22.128000
--4ds9bnG-WijS3-W773egmV2-qxb8LBZeUfEr
Content-Disposition: form-data; name="file"; filename="button_no.png"
Content-Type: image/png
Content-Transfer-Encoding: binary


--4ds9bnG-WijS3-W773egmV2-qxb8LBZeUfEr
Content-Disposition: form-data; name="thumbnail"; filename="button_yes.png"
Content-Type: image/png
Content-Transfer-Encoding: binary


--4ds9bnG-WijS3-W773egmV2-qxb8LBZeUfEr--


[no cookies]

Request Headers:
Connection: close
Content-Length: 107452
Content-Type: multipart/form-data; boundary=4ds9bnG-WijS3-W773egmV2-qxb8LBZeUfEr
Host: *****.mybluemix.net
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_151)

0 个答案:

没有答案