带有JSON内容+多个mutipart文件的Spring MVC Rest服务 [英] Spring MVC rest service with JSON content + multiple mutipart files

查看:204
本文介绍了带有JSON内容+多个mutipart文件的Spring MVC Rest服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要spring rest服务,该服务需要将输入作为JSON内容和多个mutipart文件.

Need a spring rest service which needs to take input as JSON content and Multiple mutipart files.

推荐答案

下面是我在Spring MVC控制器中处理JSON内容+多个部分的方法

Below is the approach I followed to handle JSON content + multiple multiparts in spring MVC controller

后端实施:

@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes =    {"multipart/form-data"})
public
@ResponseBody
List<String> handleFileUpload(MultipartHttpServletRequest multipartHttpServletRequest) {
InputStream jsonSteam = multipartHttpServletRequest.getFile("json").getInputStream();
InputStream fileStream1 = multipartHttpServletRequest.getFile("file1").getInputStream();
InputStream fileStream2 = multipartHttpServletRequest.getFile("file2").getInputStream();
}

前端实施:

请求有效负载:

------WebKitFormBoundaryhKn3wrSAw57pRAso
Content-Disposition: form-data; name="file1"; filename="deleme_bkup.sql"
Content-Type: text/x-sql


------WebKitFormBoundaryhKn3wrSAw57pRAso
Content-Disposition: form-data; name="file2"; filename="source.sql"
Content-Type: text/x-sql


------WebKitFormBoundaryhKn3wrSAw57pRAso
Content-Disposition: form-data; name="json"; filename="blob"
Content-Type: application/json


------WebKitFormBoundaryhKn3wrSAw57pRAso--
Response Headersview source

RequestHeaders:

Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:5533
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryhKn3wrSAw57pRAso
Host:localhost:8080
Origin:http://localhost:8080
Pragma:no-cache

这篇关于带有JSON内容+多个mutipart文件的Spring MVC Rest服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆