oracle adf - ADF: How to get path of file when using InputFile Component -
i using jdeveloper version 11.1.1.5.0. in use case have created mail client send mail program used adf inputfile component attach file on mail.
but problem inputfile component return path of file(only file name). , in mail program datasource class use full path access file name.
uploadedfile uploadfile=(uploadedfile) actionevent.getnewvalue(); string fname= uploadfile.getfilename();//this line file name.
so how can full path using adf inputfile component or other way fulfill requirement.
you save uploaded file in path @ server. take care naming file, because of concurrency of users should follow policy it, example, adding te time in milliseconds name of file. this...
private string writetofile(uploadedfile file) { servletcontext servletctx = (servletcontext)facescontext.getcurrentinstance().getexternalcontext().getcontext(); string filedirpath = servletctx.getrealpath("/files/tmp"); string filename = gettimeinmilis()+file.getfilename(); try { inputstream = file.getinputstream(); outputstream os = new fileoutputstream(filedirpath + "/"+filename); int readdata; while ((readdata = is.read()) != -1) { os.write(readdata); } is.close(); os.close(); } catch (ioexception ex) { ex.printstacktrace(); } return filename; }
this method returns new name of uploaded file. can replace gettimeinmilis() naming policy like.
Comments
Post a Comment