繁体   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