I have the problem with video rewind on my site.
I figure out that problem with http headers.
My current controller method which returns video:
@RequestMapping(method = RequestMethod.GET, value = "/testVideo")
@ResponseBody
public FileSystemResource testVideo(Principal principal) throws IOException {
return new FileSystemResource(new File("D:\\oceans.mp4"));
}
How to rewrite following code with byte-range supporting?
P.S.
I have seen following example http://balusc.blogspot.in/2009/02/fileservlet-supporting-resume-and.html
But this code looks hard for me and I cannot understand it. I hope that in spring mvc exists way simpler.
Depending on what you're trying to achieve, it may make sense for you to map the request by to the container's default servlet.
I.e., during initialization:
The answer of Leandro worked perfectly for me. I only changed the InputStream with a RandomAccessFile, it is performing better to access a random point inside a file.
Here is the class MultipartFileSender
Try this simple code .
Update :
Its wrapping the Spring Jersey jersey.java.net RESTful implementation with spring MVC.
For pure Spring mvc use below code.
IOUtils is from apache common jar
The request for support for http byte-range was open at the time of this answer but is fixed in Spring 4.2.RC1. Check jira SPR-10805 or, the PR here.
But based on the code that you linked in your question, Davin Kevin built a solution that could work for your request.
Code for MultipartFileSender:
Use in Controller:
If you want to avoid
MimeTypeUtils
, you can useFiles.probeContentType(Path path)
. That will use the default implementation of the system.woww, The answer of Leandro so briliant. just create service file follow him and use in controller. here my after follow his guidelines