首页 > 解决方案 > 使用 ReactiveGridFsTemplate Spring Webflux 在 mongodb 中存储 base64 图像

问题描述

以前,我能够使用GridFsTemplate存储base64图像,如下所示。

val imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary("base64 image string")
gridFsTemplate.store(ByteArrayInputStream(imageBytes), "imagename")

然而ReactiveGridFsTemplate的store()函数接受一个类型为 的参数。如何将 base64 图像转换为该类型?Flux<DataBuffer>

标签: springspring-bootkotlinspring-webfluxspring-mongodb

解决方案


我相信您可以将 AsyncStreamHelper.toAsyncInputStream 与 base64 一起用作字节数组。

我现在正在使用手机,所以我无法编写示例,但您可以在此处查看课程的倒数第二个方法:https ://github.com/BayviewComputerClub/smoothie-web/blob/master/src/主/java/club/bayview/smoothieweb/repositories/TestDataRepository.java


推荐阅读