首页 > 解决方案 > IBM MobileFirst Adapter 接受 Multipart 请求

问题描述

我是 IBM MobileFirst 的新手,我正在尝试使用 Multipart 上传图像。每当我尝试调用 API 上传图像时,我都会在 Postman 中收到错误消息,提示找不到 415 内容或 500 服务器错误。所以我只是想知道 IBM mobile first java 适配器是否接受多部分请求

我附上了使用的 Java 代码,但这些都不起作用:

1)

@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
            public @ResponseBody
            String uploadFileHandler(@RequestParam("file") MultipartFile file) 
            {
                return null;
            
            }
  1. 也试过这个:

       @POST
       @Path("/upload")
       @Produces(MediaType.APPLICATION_JSON)
       @Consumes(MediaType.APPLICATION_JSON)
       @OAuthSecurity(enabled=false)
       public ResponseEntity<?> upload(@RequestParam("files") MultipartFile files) {
                 log.info("XXXXXXXXXXXXXXXXXXXX");
                 return null;
    

    }

  2.   @POST
      @Path("/addEmployeeAttachment")
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.MULTIPART_FORM_DATA)
      @OAuthSecurity(enabled=false)
      public @ResponseBody Map<String, Object> addEmployeeAttachment(     
              @RequestParam(required = false, value = "attachmentFile") MultipartFile attachmentFile) {
    
          log.info("xxxxxxxxxx");
          return null;
    
      }
    

标签: javaibm-mobilefirstmobilefirst-adaptersmobilefirst-servermfp

解决方案


参考 IBM Mobile 第一个开发参考文档https://www.ibm.com/support/knowledgecenter/SSHS8R_8.0.0/com.ibm.worklight.apiref.doc/apiref/c_restapi_oview.html

我们可以使用Deploy (POST)Deploys 一个多部分的压缩文件。

JSON 示例:-

{
  "ok" : false,
  "productVersion" : "8.0",
  "transaction" : {
    "appServerId" : "Tomcat",
    "description" : {
      "name" : "myname",
      "type" : "mytype",
    },
    "errors" : [
      {
        "details" : "An internal error occured.",
      },
      ...
    ],
    "id" : 1,
    "project" : {
      "name" : "myproject",
    },
    "status" : "FAILURE",
    "timeCreated" : "2014-04-13T00:18:36.979Z",
    "timeUpdated" : "2014-04-14T00:18:36.979Z",
    "type" : "UPLOAD_ARTIFACT",
    "userName" : "demouser",
  },
}

标准错误代码:-

Errors 400 No deployable data is provided. 403 The user is not
authorized to call this service. 404 The corresponding runtime is not
found or not running. 500 An internal error occurred.

您能否参考一下如何使用 Java 发出多部分/表单数据 POST 请求?也是。

我希望它能帮助你更多地了解多部分 API。


推荐阅读