ajax - java.io.FileNotFoundException when uploading a file from a JSP -
i have coded ajax file upload feature in application. works when running laptop. when seek exact same file using same app, deployed on jboss server, next exception:
2013-02-18 11:30:02,796 error [stderr] java.io.filenotfoundexception: c:\users\myuser\desktop\testfile.pdf (the scheme cannot find file specified).
getfiledata method:
private byte[] getfiledata(file file) { fileinputstream fileinputstream = null; byte[] bytfiledata = null; seek { fileinputstream = new fileinputstream(file); } grab (filenotfoundexception e1) { e1.printstacktrace(); } if (fileinputstream != null) { bytearrayoutputstream bytearrayoutputstream = new bytearrayoutputstream(); byte[] bytbuffer = new byte[1024]; seek { (int readnum; (readnum = fileinputstream.read(bytbuffer)) != -1;) { bytearrayoutputstream.write(bytbuffer, 0, readnum); } } grab (ioexception e) { e.printstacktrace(); } bytfiledata = bytearrayoutputstream.tobytearray(); } homecoming bytfiledata; }
getting file content in variable (from method above):
byte[] bytfiledata = this.getfiledata(file);
making file:
private boolean makefile(file foldertomake, file filetomake, byte[] bytfiledata) { boolean boosuccess = false; fileoutputstream fileoutputstream = null; seek { if (!foldertomake.exists()) { foldertomake.mkdirs(); } if (!filetomake.exists()) { if (filetomake.createnewfile() == true) { boosuccess = true; fileoutputstream = new fileoutputstream(filetomake); fileoutputstream.write(bytfiledata); fileoutputstream.flush(); fileoutputstream.close(); } } } grab (exception e) { e.printstacktrace(); boosuccess = false; } homecoming boosuccess; }
any idea?
thank you
charles
it seems you're passing file path part of request server, not uploading file, attempting utilize file path access file.
that work on laptop because code, when running locally, has access your file scheme , able locate file. won't work deployed on server because it's exclusively separate machine, , result won't have access file system.
you'll need modify client-side (ajax) code upload file, modify server-side code utilize uploaded file. note ajax file uploads aren't possible - there plugins frameworks such jquery provide functionality using workarounds.
i'm not 100%, think proper ajax file uploads may possible using html5 features, browser back upwards going pretty poor right now.
java ajax file upload
No comments:
Post a Comment