我们正在尝试开发一种接受分段文件上传的REST服务。
我进行了以下更改:
dependencies.gradle:
compile('jersey-multipart:1.2')
web.xml:
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
WADL changes:
<resource path="/upload">
<method name="POST" id="upload" resource-operation="POST /upload">
<request>
<representation mediaType="multipart/form-data" />
</request>
<response status="200">
<representation element="n:Response" mediaType="application/xml"/>
</response>
</method>
</resource>
Java:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/xml")
public Response uploadMethod(FormDataMultiPart file) throws FileNotFoundException {
<>some code here.....<> }
在POSTMAN的“正文”中,我们选择“表单数据”选项,然后将pdf文件上传到键值对的值部分。
当我用POSTMAN发出此请求时,出现以下错误:
Caused By: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=multipart/form-data
....
....
....
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:247)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86)
Truncated. see log file for complete stacktrace
请让我知道解决此问题所需的更改。
我通过此链接进行了上述更改: https://howtodoinjava.com/jersey/jersey-file-upload-example/