Brief introduction
UPLOAD4J is a lightweight HTTP file upload framework, easy to use, efficient, functional, and get rid of the traditional HTTP file upload framework cumbersome.
Upload4j was born not to address all of the upload requirements, but to focus on the basic general requirements.
Upload4j brought the
· The implementation of the direct file stream upload, HTML form stream upload two upload mode.
· The IO operation part uses the NIO mechanism.
· File filtering is supported and filtered based on the binary header, rather than the traditional file name extension filter.
· The upload file size is not limited by memory size.
Upload4j can't give.
· File upload progress.
· Bulk upload.
Upload4j Use Example
Direct file stream upload
Enable Filter function
1 //Filter Filters2MetaFilter MetaFilter =NewMetaFilter ();3Metafilter.add (". jpg", "ffd8ff");//allowable file types, params: file suffix name, file header hex string4map<string, string> metamap =NewHashmap<string, string>();5Metamap.put (". png", "89504E47");6Metafilter.frommap (METAMAP);//add allowed file types in bulk7 8 //Configuration9Metafilterconfig metafilterconfig = Metafilterconfig.custom (). Setbuffersize (8192)//default 8192B, Unit BTen. setmaxfilesize (1024 * 1024)//limit file maximum 1M, Unit B One. SetFilter (MetaFilter)//Filter Filters A. Setrequest (Request)//reads a file stream from the body of the request object -. Setfilenamewithoutsuffix ("123")//save file name (without extension, auto-identify) -. Setsavepath ("/home/user1/upload/img/2015/09/24/");//Save Path the - //Upload -Streamupload streamupload =Newstreamupload (); -Simpleuploadresponse response =streamupload.upload (metafilterconfig); + - //Upload Results + if(Response.issuccess ()) {//Success A //get File Save full path at Response.getfilepath (); - // ...... -}Else{//failed - //determine if failure is controllable - if(response.getexception () = =NULL){//controllable - //get the reason for failure in response.geterrmsg (); - // ...... to}Else{//not controllable + //throwing Exceptions directly - Throwresponse.getexception (); the } *}
Do not enable the filtering function
1 //Configuration2Streamconfig streamconfig = Streamconfig.custom (). Setbuffersize (8192)//default 8192B, Unit B3. setmaxfilesize (1024 * 1024)//limit file maximum 1M, Unit B4. Setrequest (Request)//reads a file stream from the body of the request object5. Setfilenamewithsuffix ("123.jpg")//Save full file name (with extension)6. Setsavepath ("/home/user1/upload/img/2015/09/24/");//Save Path7 8 //Upload9Streamupload streamupload =Newstreamupload ();TenSimpleuploadresponse response =streamupload.upload (streamconfig); One A //Upload Results - if(Response.issuccess ()) {//Success - //get File Save full path the Response.getfilepath (); - // ...... -}Else{//failed - //determine if failure is controllable + if(response.getexception () = =NULL){//controllable - //get the reason for failure + response.geterrmsg (); A // ...... at}Else{//not controllable - //throwing Exceptions directly - Throwresponse.getexception (); - } -}
HTML form stream upload
Enable Filter function
1 //Filter Filters2MetaFilter MetaFilter =NewMetaFilter ();3Metafilter.add (". jpg", "ffd8ff");//allowable file types, params: file suffix name, file header hex string4map<string, string> metamap =NewHashmap<string, string>();5Metamap.put (". png", "89504E47");6Metafilter.frommap (METAMAP);//add allowed file types in bulk7 8 //Configuration9Metafilterconfig metafilterconfig = Metafilterconfig.custom (). Setbuffersize (8192)//default 8192B, Unit BTen. setmaxfilesize (1024 * 1024)//limit file maximum 1M, Unit B One. SetFilter (MetaFilter)//Filter Filters A. Setrequest (Request)//reads a file stream from the body of the request object -. Setfilenamewithoutsuffix ("123")//save file name (without extension, auto-identify) -. Setsavepath ("/home/user1/upload/img/2015/09/24/");//Save Path the - //Upload -Formupload formupload =Newformupload (); -Simpleuploadresponse response =formupload.upload (metafilterconfig); + - //Upload Results + if(Response.issuccess ()) {//Success A //get File Save full path at Response.getfilepath (); - // ...... -}Else{//failed - //determine if failure is controllable - if(response.getexception () = =NULL){//controllable - //get the reason for failure in response.geterrmsg (); - // ...... to}Else{//not controllable + //throwing Exceptions directly - Throwresponse.getexception (); the } *}
Do not enable the filtering function
1 //Configuration2Formconfig formconfig = Formconfig.custom (). Setbuffersize (8192)//default 8192B, Unit B3. setmaxfilesize (1024 * 1024)//limit file maximum 1M, Unit B4. Setrequest (Request)//reads a file stream from the body of the request object5. Setfilenamewithoutsuffix ("123")//save file name (without extension, auto extract)6. Setsavepath ("/home/user1/upload/img/2015/09/24/");//Save Path7 8 //Upload9Formupload formupload =Newformupload ();TenSimpleuploadresponse response =formupload.upload (formconfig); One A //Upload Results - if(Response.issuccess ()) {//Success - //get File Save full path the Response.getfilepath (); - // ...... -}Else{//failed - //determine if failure is controllable + if(response.getexception () = =NULL){//controllable - //get the reason for failure + response.geterrmsg (); A // ...... at}Else{//not controllable - //throwing Exceptions directly - Throwresponse.getexception (); - } -}
Browse UPLOAD4J Projects
Upload4j secure, efficient, and easy-to-use Java HTTP file upload framework