java - 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;
}
也试过这个:
@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;
}
-
@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; }
解决方案
参考 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。
推荐阅读
- python - 在 Python 上运行的语法错误
- arrays - 命令在终端中工作,但不在 Bash 脚本中
- python - 如何将多个元素附加/扩展到一个数组中?
- jquery - 当用户单击表单按钮时显示模式并在用户单击 codeigniter 中的模式按钮时提交表单
- python - 在 otree 游戏设计中使用 Django 将数据从表单保存到数据库
- ios - IOS天气应用
- node.js - node.js then() 不工作
- python - xgboost回归预测相同的值
- java - 使用 new File(directory).mkdir() 创建文件时出错
- java - Java Compute C(n,k) 和使用 biginteger 的阶乘