Hybris MediaModel如何获取字节 [英] Hybris MediaModel how to get Bytes

查看:114
本文介绍了Hybris MediaModel如何获取字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hybris中有什么方法可以从MediaModel中获取所有字节吗?当我想实例化PdfReader时,我需要传递文件的路径或ByteArrayInputStream.如何将MediaModel转换为字节数组?

Is there any way in Hybris to obtain all the bytes from a MediaModel ? When I want to instantiate a PdfReader , I need to pass either the Path of the File OR the ByteArrayInputStream. How can I transform the MediaModel into a Byte Array?

推荐答案

您可以使用MediaService

You can use MediaService

@Resource
private MediaService mediaService;
//...
final MediaModel mediaModel= mediaService.getMedia("mediaName");
final InputStream inputStream = mediaService.getStreamFromMedia(mediaModel);

然后,您可以传递InputStream或将其转换为所需的格式,例如 ByteArrayInputStream

Then you can pass InputStream or converting it to the format you want like ByteArrayInputStream

您还可以像

byte[] bytes = IOUtils.toByteArray(is);

这篇关于Hybris MediaModel如何获取字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆