![](/img/trans.png)
[英]Put zip files from local directory into a list in java springboot
[英]Springboot HATEOAS for PDF, Image and Zip Files
這是我第一次與 HATEOAS 所有人一起工作,我已經戛然而止。 這是我的問題,我有一個應用程序可以將文本從文本區域轉換為 pdf 並將 pdf 轉換為圖像。 我的問題是我將兩者都作為 ResponseEntity<byte[]> 發回。 這是從文本到 pdf 端點的示例成功響應:
// Get PDF from conversion result
byte[] res;
res = this.textToPDFService.convertTextToPdf(input);
// Create pdf name
DateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy:hh:mm:ss");
String currentDateTime = dateFormatter.format(new Date());
// Prepare Headers to open PDF on the client
String headerKey = "Content-Disposition";
String headerValue = "inline; filename=pdf_" + currentDateTime + ".pdf";
// Send a successful response
return ResponseEntity.ok()
.header(headerKey, headerValue)
.contentType(MediaType.APPLICATION_PDF)
.body(res);
問題:
非常歡迎任何關於如何將這些文件添加到 JSON 響應的其他好的資源。
您可以將這些文件的臨時流(下載)鏈接添加到您的 HATEOAS。
或者您可以返回您生成的編碼文件的 base64 值將 pdf 轉換為 base64
return ResponseEntity.ok(ENCODED_STRING).build();
實際上,我最終在響應實體中發送了一個 byte[],Springboot 使用 Base64 編碼自動對其進行了轉換。 然后在客戶端,我通過提取對象然后提供我設置的密鑰從 LinkedHashMap<String, String> 中的 JSON 接收它。 一旦我有了這個值,我就使用內置的 Base 64 解碼器(沒有包/外部存儲庫)對其進行解碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.