如何解决处理来自弹簧支架控制器的多部分响应
我有这样的控制器方法
@PostMapping(path = "/downloadAttachment",produces = "application/octet-stream")
public ResponseEntity<?> downloadAttachment(@Valid @RequestBody Attachment attachmentModel) {
refreshProp(false);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
try {
String byteRes = null;
JSONArray responseFromDownloadAttachment =
databaseOperations.downloadAttachment(attachmentModel);
if (responseFromDownloadAttachment.length() == 0) {
return new ResponseEntity<>("",HttpStatus.NO_CONTENT);
}
else {
for (int blobRes = 0; blobRes < responseFromDownloadAttachment.length(); blobRes++) {
JSONObject blobObj = responseFromDownloadAttachment.getJSONObject(blobRes);
if (blobObj != null) {
byteRes = (String) blobObj.getString("file");
}
}
}
byte[] byteArrray = byteRes.getBytes();
return new ResponseEntity<>(byteArrray,HttpStatus.OK);
} catch (Exception e) {
log.error("Exception occurred!" + e);
e.printStackTrace();
JSONObject errObj = new JSONObject();
errObj.put("status","E");
errObj.put("message",e);
return new ResponseEntity<>(errObj.toString(),HttpStatus.INTERNAL_SERVER_ERROR);
}
}
我正在发送字节数组作为响应。但是我不确定我将从服务层获取哪种类型的文件。它可以是xlsx,txt,png,jpg或任何多媒体的任何形式。我正在设置标头八位字节流,也产生八位字节流。我可以使用八位字节流来处理这些类型的响应吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。