Hybris MediaModel how to get Bytes

蓝咒 提交于 2019-12-02 13:49:52

问题


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?


回答1:


You can use MediaService

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

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

You can also convert it byte Array like this

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


来源:https://stackoverflow.com/questions/58412355/hybris-mediamodel-how-to-get-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!