簡體   English   中英

將不在類路徑中的文件加載到 Spring 資源中?

[英]Loading a file not in the classpath into a Spring Resource?

我目前有一個 Spring API 服務,它接受一個 Base64 字符串 img 並對其進行解碼。

String imageDataBytes = img.substring(img.indexOf(",")+1);
InputStream stream = new ByteArrayInputStream(Base64.decodeBase64(imageDataBytes));

我想將流的內容加載到 Resource 類上。 但到目前為止,我的研究告訴我我只能通過 URL 或文件路徑加載資源,而我在這里沒有。 我能做什么?

您可以使用 ByteArrayResource。 它在構造函數中接受一個字節數組。 這是文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM