spring - 使用 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>
解决方案
我相信您可以将 AsyncStreamHelper.toAsyncInputStream 与 base64 一起用作字节数组。
我现在正在使用手机,所以我无法编写示例,但您可以在此处查看课程的倒数第二个方法:https ://github.com/BayviewComputerClub/smoothie-web/blob/master/src/主/java/club/bayview/smoothieweb/repositories/TestDataRepository.java
推荐阅读
- react-native - How to reverse playback with Expo Audio
- php - WordPress pagination, offset and count users with WP_User_Query()
- tensorflow - After creating an embedding layer using a tensorflow placeholder, how is the tf.nn.embedding_lookup() function used with it?
- for-loop - How to select two table columns in the same for loop
- r - Multi regression of unbalanced data
- objective-c - 如何从用 JSONModel 编写的 NSArray 中删除重复数据?
- spring-boot - Spring boot does not fail for missing @Value property when it comes from custom starter
- ruby-on-rails - 构建 Rails 项目的正确方法
- javascript - data from php script in javascript wrong output
- php - Front-page.php url 蛞蝓