jsf - p:upload file doesn't work with pdf extension neither of the rest of extension like png,docx,jpeg,gif? -
and cant' store file more 10mb primary problrm why doesn't except pdf file??? managedbean file upload function :-
public void fileuploadlistener(fileuploadevent e) throws ioexception, exception { this.file = e.getfile(); file ostream = new file("c:\\test.pdf"); courseresourcebean.update(item); ostream.createnewfile(); long sss = file.getsize(); inputstream inputstream = file.getinputstream(); fileoutputstream outputstream = new fileoutputstream(ostream); byte[] buffer = new byte[sss.bytevalue()]; int lenght; while ((lenght = inputstream.read(buffer)) != -1) { outputstream.write(buffer, 0, lenght); } outputstream.close(); facescontext.getcurrentinstance().addmessage(null, new facesmessage("file uploaded successfully" + file.getsize())); string extension = file.getcontenttype(); }
file download function :-
public void prepdownload(long id) throws exception { file files = new file("c:\\test.pdf"); inputstream input = new fileinputstream(files); externalcontext externalcontext = facescontext.getcurrentinstance().getexternalcontext(); setdownload(new defaultstreamedcontent(input, externalcontext.getmimetype(files.getname()), files.getname())); system.out.println("prep = " + download.getname()); }
and xhtml page upload :-
<p:outputlabel value="#{msg.coursename}, #{msg.inarabic}" style="text-align: right"/> <p:fileupload value="#{courseresourcemb.file}" mode="advanced" sizelimit="200000000000" fileuploadlistener="#{courseresourcemb.fileuploadlistener}" update="msg11" > </p:fileupload>
downlad:-
<p:commandbutton id="downloadlink" value="download" actionlistener="#{courseresourcemb.prepdownload(item.id)}" ajax="false"> <p:filedownload value="#{courseresourcemb.download}" /> </p:commandbutton>
Comments
Post a Comment