multithreading - Upload a file in a separate thread in a java webapp -


i need make form users can upload big files (>200mo). wanted launch uploads in separate threads users can launch 3-4 uploads , else. problem generated .tmp file deleted when run secondary thread. use struts2.

what struts2 gives me:

private string uploadcontenttype; private string uploadfilename; private file upload; 

i transfer information thread using constructor

mythread thread=new mythread (sourcename, uploadfilename, upload, user, database); thread.start(); 

in run() method:

system.out.println("src file name: " + myfile); system.out.println("dst file name: " + myfilefilename);  file destfile  =new file(upload_directory, myfilefilename); fileutils.copyfile(myfile, destfile); 

and error:

src filename: c:\***myeclipsepath***\upload_1949ed75_1002_4ccf_b198_ 25faff66563a_00000003.tmp dst file name: books.xml java.io.filenotfoundexception:     c:\***myeclipsepath***\upload_1949ed75_1002_4ccf_b198_ 25faff66563a_00000003.tmp  (le fichier spécifié est introuvable)    @ java.io.fileinputstream.open0(native method)    @ java.io.fileinputstream.open(unknown source)    @ java.io.fileinputstream.<init>(unknown source)    @ org.apache.commons.io.fileutils.docopyfile(fileutils.java:1068)    @ org.apache.commons.io.fileutils.copyfile(fileutils.java:1021)    @ org.apache.commons.io.fileutils.copyfile(fileutils.java:968)    @ bo.threads.mythread .run(mythread .java:68) 

when debug step-by-step see .tmp file disappear when call thread.start().

so how can upload files on other threads main 1 ?

running multiple threads in webapp never required , bad idea.

you not aware can upload multiple files concurrently. can tweak configuration settings allow files size higher default threshold (both per-file , per-request).

the thing remaining accomplish requirement of letting user else after started uploading can achieved either:

  1. opening upload page in new tab, run standard submit (user change previous tab manually)
  2. open upload action in new tab target="_blank" (user change previous tab manually)
  3. upload through ajax (but huge size might encounter limits , problems).

i'd go solution n.2.


edit

thank advice, should work how can close automatically tab in action ?

there many ways, example can return jsp consisting of following content:

<script>     window.close(); </script> 

but consider informing user of positive (or negative) outcome of operation more descriptive, non-self-closing page, or (if close tab) listener of kind other tab (that perfect, , new question, try making work before).


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -