提问者:小点点

使用Swagger上传CSV文件时出现问题


我正在尝试用Swagger2.0tu实现一个RESTful API,用Java后端上传一个CSV文件; 这是API的swagger定义:

/mobileCommunications/importCallDetails:
  post:
    operationId: importCallDetails
    summary: Uploads a file that contains the call details for a specific period.
    tags:
      - MobileCommunications
    consumes:
      - multipart/form-data
    parameters:
      - in: formData
        name: upfile
        type: file
    responses:
       '200':
          description: file uploaded successfully

这就是Swagger生成的代码:

@POST
@Path("/importCallDetails")
@Consumes({ "multipart/form-data" })
@Produces({ "application/json; charset=utf-8" })
@io.swagger.annotations.ApiOperation(value = "Uploads a file that contains the call details for a specific period.", notes = "", response = Void.class, tags={ "MobileCommunications", })
@io.swagger.annotations.ApiResponses(value = { 
    @io.swagger.annotations.ApiResponse(code = 200, message = "file uploaded successfully", response = Void.class) })
public Response importCallDetails(MultipartFormDataInput input,@Context SecurityContext securityContext,@Context Request request,@Context HttpServletRequest httpServletRequest) throws ApplicationException;

这是我的控制器代码(它根本不执行,这就是为什么它是空的):

@Override
public Response importCallDetails(MultipartFormDataInput input, SecurityContext securityContext, Request request,
        HttpServletRequest httpServletRequest) throws ApplicationException {

    return null;
}

但是,每当我尝试上传文件时,我仍然会在后端收到此错误:

Caused by: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=multipart/form-data; boundary=----WebKitFormBoundaryvmfNnOPmhX557ZUx, type=interface org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput, genericType=interface org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput.

我已经被这个问题困住了一个星期了,但是我没有在解决这个问题上取得任何进展,所以任何帮助都将在这里发挥作用:)

谢谢


共1个答案

匿名用户

对我来说,这似乎和大摇大摆无关。 这是Java密码的问题。

也许可以看看这里和/或分享您的控制器代码。