使用 ReactiveGridFsTemplate Spring Webflux 在 mongodb 中存储 base64 图像
Store a base64 image in mongodb using ReactiveGridFsTemplate Spring Webflux
以前,我能够使用 GridFsTemplate 存储 base64 图像,如下所示。
val imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary("base64 image string")
gridFsTemplate.store(ByteArrayInputStream(imageBytes), "imagename")
然而,ReactiveGridFsTemplate 的 store() 函数接收一个 Flux<DataBuffer>
类型的参数。如何将 base64 图像转换为该类型?
我相信你可以使用 AsyncStreamHelper.toAsyncInputStream 和 base64 作为字节数组。
我现在在 phone 上,所以我不能写一个例子,但是你可以在这里查看 class 的倒数第二个方法:https://github.com/BayviewComputerClub/smoothie-web/blob/master/src/main/java/club/bayview/smoothieweb/repositories/TestDataRepository.java
以前,我能够使用 GridFsTemplate 存储 base64 图像,如下所示。
val imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary("base64 image string")
gridFsTemplate.store(ByteArrayInputStream(imageBytes), "imagename")
然而,ReactiveGridFsTemplate 的 store() 函数接收一个 Flux<DataBuffer>
类型的参数。如何将 base64 图像转换为该类型?
我相信你可以使用 AsyncStreamHelper.toAsyncInputStream 和 base64 作为字节数组。
我现在在 phone 上,所以我不能写一个例子,但是你可以在这里查看 class 的倒数第二个方法:https://github.com/BayviewComputerClub/smoothie-web/blob/master/src/main/java/club/bayview/smoothieweb/repositories/TestDataRepository.java