Approximate architecture:
Front End: Html5+ajax
Backend: Java (Struts framework related)
Problems encountered:
Backstage coder provides me with an interface./file/uploader.do?upfile=, let me upload the file corresponding to upfile this parameter, the front-end use is webuploader this upload plugin, do not know how this thing custom parameters ... After a variety of Google, Baidu, found the following two kinds of solutions:
1, the interface does not need to specify parameters, directly with Request.getinputstream () binary way to accept the uploaded file, But here special attention, need to webuploader this configuration
Sendasbinary Change to True
varuploader =webuploader.create ({swf:'./js/webuploader/uploader.swf ', Server:common. Base_url_dev+ '/file/upload.do ', pick:' #picker ', Duplicate:false, resize:false, Auto:true, Filenumlimit:5, Sendasbinary:true,//indicates that the file is uploaded using binary modefilesinglesizelimit:5242880, //fileType: ' Rar,zip,doc,xls,docx,xlsx,pdf 'Accept: {title:' Intotypes ', Extensions:' Rar,zip,doc,xls,docx,xlsx,pdf ', Mimetypes:'. Rar,.zip,.doc,.xls,.docx,.xlsx,.pdf ' } });
2, use common-fileupload this plug-in received, not much said (backend coder self-knowledge, provide a copy of the relevant documents: http://blog.csdn.net/a352193394/article/details/7477041)
And on the Internet when the information to see a lot of friends are asking, Java backend how to write? How do I accept parameters? Here I have practiced once, for everyone to do the answer, first thanks to our back-end coder, let me suddenly enlightened:
When I gave him the interface does not pass the parameters of the upload file, he saw the Tomcat log print out three parameters, respectively, File,filecontenttype,filefilenamez these three parameters, file this parameter after debugging, I passed the file, Then we guess there is a default parameter called "File", go to Webuploader this api has been searched to prove that our guesses are correct, such as:
Sure enough, there is a default parameter called "File" ...... .....
At this point the problem is solved, paste the following code:
varuploader =webuploader.create ({swf:'./js/webuploader/uploader.swf ', Server:common. Base_url_dev+ '/file/upload.do ', pick:' #picker ', Duplicate:false, resize:false, Auto:true, Filenumlimit:5, Fileval:"Upload",//indicates the name of the parameter, and the background also uses this parameter to receive the filefilesinglesizelimit:5242880, //fileType: ' Rar,zip,doc,xls,docx,xlsx,pdf 'Accept: {title:' Intotypes ', Extensions:' Rar,zip,doc,xls,docx,xlsx,pdf ', Mimetypes:'. Rar,.zip,.doc,.xls,.docx,.xlsx,.pdf ' } });
Welcome to shoot the bricks ..... ......
Webuploader plug-in usage analysis