【问题标题】:Store a base64 image in mongodb using ReactiveGridFsTemplate Spring Webflux使用 ReactiveGridFsTemplate Spring Webflux 在 mongodb 中存储 base64 图像
【发布时间】:2020-06-09 11:05:36
【问题描述】:

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

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

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

【问题讨论】:

    标签: spring spring-boot kotlin spring-webflux spring-mongodb


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2020-05-28
      • 2012-09-14
      • 1970-01-01
      • 2017-01-11
      • 1970-01-01
      • 2012-02-06
      • 2014-05-11
      • 1970-01-01
      相关资源
      最近更新 更多