I learned that I can't just set a local URL to the object
tag of the HTML, which led me to search a bit more. As a result, I saw this post which is really detailed and well documented. But I don't know if this is the proper approach for me to take and I really know nothing about JSF.
What I want to do is to send a PDF file in a web browser or simply embed a PDF file to the browser which is from the local path. Is there a way doing this in Spring? I used commons-fileupload in uploading the PDF to the local path as they say a good practice. Now the thing left is to display it.
By the way, I'm using Spring MVC
if this will also help to clarify the approach I need.
Update:
What I learned so far is to use @ResponseBody
to return the bytes, so I did try this:
@ResponseBody
@RequestMapping(value = "/get/pdf", produces="application/pdf")
public byte[] download( HttpServletResponse response ) throws IOException {
response.setContentType( "application/pdf" );
byte[] test = null;
try
{
String path = new FileDAO().getFilePath( 1 );
File file = new File( path );
test = new byte[ ( int ) file.length() ];
FileInputStream fileInputStream = new FileInputStream( file );
fileInputStream.read( test );
}
catch( Exception e )
{
e.printStackTrace();
}
return test;
}
The result to the web page is like this.
I want to display the PDF file in object
or iframe
tag.