无疑又傻福利局的问题!我有一个Grails控制器包含一个视频文件(* .MP4文件,以准确)的内容的字节数组。我熟悉如何呈现JSON,XML等基本类型,从一个Grails控制器,但是我找不到,展示了如何输出视频的任何实例。从本质上说我要做到以下几点:
渲染字节作为MP4
我意识到我可能需要一个结构,例如:
渲染(文字:< XML>一些XML< / XML>中,则contentType:视频/ MPEG,编:UTF-8)
但我并不清楚我是如何得到的字节数组中there.Obviously我不是渲染类似HTML的内容的专家。我一直躲在库函数太长了!任何指针引用或例子是很多AP preciated。
所以,如果它有助于指向正确的方向的意见,与视频中的字节从我读的的JetS3t库中的S3对象来了。
解决方案 的OutputStream OUT = response.getOutputStream()
//设置字节数组
byte []的内容= yourS3Object.getBytes()
response.setContentLength(content.size())
response.addHeader(内容处置,附件;文件名= $ {yourS3Object.fileName})
response.addHeader(内容型,视频/ QuickTime的)
out.write(内容)
out.close()
这是应该做的伎俩。
No doubt another silly newb question! I have a byte array in a Grails controller that contains the contents of a video file (an *.mp4 file to be exact). I am familiar with how to render JSON, XML and other basic types from a grails controller but I can't find any examples showing how to output video. In essence I want to do the following:
render bytes as MP4
I realize that I probably need a construct such as:
render(text:"<xml>some xml</xml>",contentType:"video/mpeg",encoding:"UTF-8")
but I'm not clear how I get the byte array in there.Obviously I am not an expert on rendering html-like content. I've been hiding behind library functions too long! Any pointers to a reference or example would be much appreciated.
So if it helps point the advice in the right direction, the bytes with the video are coming from an S3 object that I am reading with the jets3t library.
解决方案 OutputStream out = response.getOutputStream()
//set up byte array
byte[] content = yourS3Object.getBytes()
response.setContentLength(content.size())
response.addHeader("Content-disposition", "attachment; filename=${yourS3Object.fileName}")
response.addHeader("Content-type", "video/quicktime")
out.write(content)
out.close()
That should do the trick.