java ee - Uploading a file, Spring MVC + CloudBees -


i have worked on local tomcat's server , i've deployed application cloudbees. works great apart uploading file server's directory.

i have such piece of code in controller, worked me on localhost:

@requestmapping("/main/admin/upload") public modelandview fileuploaded(         @modelattribute("uploadedfile") fileupload uploadedfile,         final httpservletrequest request,         final httpservletresponse response, bindingresult result) {      inputstream inputstream = null;     outputstream outputstream = null;     string pdfdirectory = uploadedfile.getpdfdirectory();     multipartfile file = uploadedfile.getfile();     string filename = file.getoriginalfilename();      try {         inputstream = file.getinputstream();          string pdffiledirectory = request.getsession().getservletcontext()                 .getrealpath("/")                 + "resources\\pdf\\" + pdfdirectory + "\\";         file newfile = new file(pdffiledirectory + filename);         if (!newfile.exists()) {             newfile.createnewfile();         }         outputstream = new fileoutputstream(newfile);         int read = 0;         byte[] bytes = new byte[1024];          while ((read = inputstream.read(bytes)) != -1) {             outputstream.write(bytes, 0, read);         }     } catch (ioexception e) {         e.printstacktrace();     }      return new modelandview("redirect:/main/admin"); } 

i'm not sure if line working correctly:

request.getsession().getservletcontext().getrealpath("/") 

i'm sure folders created, because have added them manually in eclipse project. i've added manually files these folders before extracting cloudbees , these files accessible, when try upload file using above code, doesn't work.

filesystem not persistent on cloud, not practice upload files file system in same way on hard disk.

application being redeployed/scale-out start on distinct node, shouldn't store files there. recommend store using amazon s3 (or comparable file store) , use local ("ephemeral") filesystem temporary cache.

you can use system.getproperty("java.io.tempdir") configured local temp.

cloudbees provides 2 different examples upload files amazon s3 -you can use dropbox, google drive,..-.

more info here.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -