java - How to return a file from a controller inside an entity?
问题描述
I tried to return .pfx certificate as bytearray
public class CertificateContainer {
private CertificateType certificateType;
private byte[] certificate;
private Map<String, String> authData;
}
converting into bytearray
FileUtils.readFileToByteArray(ResourceUtils.getFile(certificateType.getPathToCertificate()))
And the controller's return
@GetMapping
public ResponseEntity<CertificateContainer> getCertificate(@RequestParam CertificateType certificateType) {
return ok(certificateService.getCertificate(certificateType));
}
On a client's side, I'm getting String instead of bytes and adding it to an array
new ByteArrayInputStream(
certificateContainer.getCertificate().getBytes()
)
after that, adding into key store and getting exception "stream does not represent PKCS12 key store". But if I add the same file from the client storage, it works properly. What I did wrong with transporting the file?
解决方案
推荐阅读
- complexity-theory - 以下代码的渐近复杂度是多少
- java - 网络不可用时无法显示 Toast 通知
- php - Laravel 验证规则,两个字段的组合需要唯一
- rest - 如何在 powershell / Powercli 中列出 vCenter (VCSA) 服务
- pandas - 如何在熊猫中有条件地求和
- c# - 使用带有 selenium 的 wait.until 时如何记录超时时间?
- python - 请提出一种编写此代码的有效方法.. For 循环需要很长时间来处理
- mysql - PHP / MYSQL通过工作但未按预期显示组的hiscores
- angular - 访问我的组件的孩子,重建它并把它放回去
- python - 从networkx中的graphframe打印标签