fcm*_*fcm 8 java rest cxf multipartform-data jackson
我一直在使用Apache服务器和Jackson一起使用和生成JSON文件的web服务.
但是,其中一个服务的方法应该能够从一个移动应用程序保存上传的图像,该应用程序向我的web服务发出多部分/表单数据POST请求,我不知道如何处理我的这种内容类型上下文.我们通常创建"Request"和"Response"对象来使用和生成JSON,但是,我担心这不适用于这种情况.
这是请求格式:
Content-type: multipart/form-data
"Description": text/plain
"Path": text/plain
"Image": image/jpeg
Run Code Online (Sandbox Code Playgroud)
如何正确使用这种请求并保存图像服务器端?
[编辑]
我设法使用以下方法来使用multipart/form-data:
public returnType savePicture(
@Multipart(value = "mode", type = "text/plain") String mode,
@Multipart(value = "type", type = "text/plain") String type,
@Multipart(value = "path", type = "text/plain") String path
@Multipart(value = "image", type = "image/jpeg") Attachment image
)
{
Run Code Online (Sandbox Code Playgroud)
但是,在尝试使用以下POST请求时:
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="mode"
T
--AaB03x
content-disposition: form-data; name="type"
M
--AaB03x
content-disposition: form-data; name="path"
c:/img/
--AaB03x
content-disposition: form-data; name="image"; filename="image.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
imgdata
--AaB03x--
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
javax.ws.rs.BadRequestException:org.apache.cxf.jaxrs.utils.multipart.MultipartReadException:找不到内容ID 类型的多部分,请求内容类型:multipart/form-data; boundary = AaB03x
例如,当我只使用模式时,它工作正常.它只会中断2个或更多参数.任何想法为什么是错的?
看来我们找到了问题所在,和请求的格式有关。正确的格式应该是:
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="mode"
T--AaB03x
content-disposition: form-data; name="type"
M--AaB03x
content-disposition: form-data; name="path"
c:/img/--AaB03x
content-disposition: form-data; name="image"; filename="image.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
imgdata--AaB03x--
Run Code Online (Sandbox Code Playgroud)
更改为这种格式使我可以使用其他参数。
| 归档时间: |
|
| 查看次数: |
11152 次 |
| 最近记录: |