【问题标题】:IBM MobileFirst Adapter accepting Multipart requestIBM MobileFirst Adapter 接受 Multipart 请求
【发布时间】:2020-12-03 23:13:21
【问题描述】:

我是 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;
    
      }
    

【问题讨论】:

  • 请详细说明您何时看到 415 以及何时看到 500 错误代码。500 HTTP 代码通常伴随着服务器日志中的错误。看到 500 代码时分享服务器日志

标签: java ibm-mobilefirst mobilefirst-adapters mobilefirst-server mfp


【解决方案1】:

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

我们可以使用Deploy (POST) 来部署多部分压缩文件。

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.

能否请您也参考How can I make a multipart/form-data POST request using Java?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    相关资源
    最近更新 更多