Sayaka617 opened a new issue #2449:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2449


   参考文件上传下载开发的文件下载接口,调用时报错“ File input parameter of null could be 
javax.servlet.http.Part / java.io.InputStream / 
org.springframework.core.io.Resource / byte[] or java.io.File, but got 
org.springframework.http.ResponseEntity.”(PartUtils.java)
   
   接口定义
   ```java
       @ApiResponses({
           @ApiResponse(code = 200, response = File.class, message = "success")
       })
       @PostMapping(value = "/export", produces = 
"application/json;charset=utf-8")
       public ResponseEntity<FileResource> export() {
           // doSomething
   
           return ResponseEntity.ok()
                   .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; 
filename=" + fileName)
                   .header(HttpHeaders.CONTENT_TYPE, getContentType(fileType))
                   .header(HttpHeaders.CONTENT_LENGTH, 
String.valueOf(content.length))
                   .body(new FileResource(content, fileName));
       }
   ```
   body体对象:
   ```java
   public class FileResource extends ByteArrayResource {
       private String downloadFileName;
   
       public FileResource(byte[] byteArray, String downloadFileName) {
           super(byteArray);
           this.downloadFileName= downloadFileName;
       }
   
       @Override
       public String getFilename() {
           return downloadFileName;
       }
   }
   ```
   debug查看org.apache.servicecomb.common.rest.filter.inner.ServerRestArgsFilter
   ```java
   Response response = (Response) 
responseEx.getAttribute(RestConst.INVOCATION_HANDLER_RESPONSE);
       ProduceProcessor produceProcessor =
           (ProduceProcessor) 
responseEx.getAttribute(RestConst.INVOCATION_HANDLER_PROCESSOR);
       Object body = response.getResult();
       if (response.isFailed()) {
         body = ((InvocationException) body).getErrorData();
       }
   
       if (null != invocation && isDownloadFileResponseType(invocation, 
response)) {
         return responseEx.sendPart(PartUtils.getSinglePart(null, body));
       }
   ```
   对比正常的文件下载接口,`Object 
body`应该是responseEntity.getBody()的内容,实际是整个responseEntity,麻烦帮忙分析一下问题。
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to