Affects: spring6

hello guys, spring6 support HttpExchange to replace feign, i try it and find it doesn't work to upload or download file

here is upload example

@PostExchange("upload")
    Response<Void> upload(@PathVariable("module") String module,
                                       @RequestPart("files") MultipartFile[] files);

the error

WebClientResponseException$UnsupportedMediaType: 415 Unsupported Media Type from POST

by HttpExchange the content-type changed from multipart/form-data to application/vnd.spring-boot.actuator.v3+json


here is download example

    @GetExchange("downloadByDbId/{dbId}")
    void downloadByDbId(HttpServletResponse response, @PathVariable("dbId") Long dbId);

the error

No suitable resolver

so my question is HttpExchange support file upload download or not, if it can give me some example, i cant find it from spring.io

Comment From: simonbasle

That application/vnd.spring-boot.actuator.v3+json makes me think you're trying to define a custom Actuator in Spring Boot or you've mistakenly put your endpoint under the actuators path ? This media type is automatically selected by Spring Boot when dealing with an Actuator endpoint, see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.endpoints.implementing-custom.web.consumes-predicates.

If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. (marking as for: stackoverflow&status: invalid as a result)

Comment From: duorouCat

return responseEntity to transfer filedata 用responseEntity来传输文件数据

byte[] bytes = new byte[1024];

byte[] file = new byte[0];

FileInputStream inputStream = IoUtil.toStream(new File(FilePathUtil.fileNameFilter(fileName)));

while (true) {
  int size = inputStream.read(bytes);
  if (size < 0) {
    break;
  }
  byte[] temp = new byte[file.length + size];
  System.arraycopy(file, 0, temp, 0, file.length);
  System.arraycopy(bytes, 0, temp, 0, file.length);
  file = temp;
}

ResponseEntity<byte[]> responseEntity = ResponseEntity.ok(file);

receive

ResponseEntity<byte[]> responseEntity = remotefileservce(...);

ByteArrayInputStream byteArrayInputStream = IoUtil.toStream(responseEntity.getBody());

but there is a problem: "Exceeded limit on max bytes to buffer : 262144", i'm working on that 可能会报错文件"Exceeded limit on max bytes to buffer : 262144" 传输大小有限制, 还在找解决方法

Comment From: kozla13

How do you create a MultipartFile from a byte[]