SwfUpload(1)swf multiple files uploading example

SwfUpload(1)swf multiple files uploading example

swfUpload need flash player. It is good and easy to use.

My action is as follow:
@RequestMapping(value = "/swfupload.do", method = RequestMethod.POST)
public void swfupload(
@RequestParam(value = "fileName", required = false) String fileName,
@RequestParam(value = "Filedata") MultipartFile file,
HttpServletResponse response) throws IOException {
logger.info("swf orginal file name = " + file.getOriginalFilename()
+ " fileName = " + fileName);
PrintWriter out = response.getWriter();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
out.write("{success:true}");
out.close();
}

My example is in easytalker project.

The html page will be as follow:
<html>
<head>
<title>SWFUpload Demo</title>
<link rel="stylesheet" type="text/css" href="./resources/component/swfupload/2.2.0.1/default.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="./resources/component/swfupload/2.2.0.1/swfupload.js"></script>
<script type="text/javascript" src="./resources/component/swfupload/2.2.0.1/swfupload.queue.js"></script>
<script type="text/javascript" src="./resources/component/swfupload/2.2.0.1/fileprogress.js"></script>
<script type="text/javascript" src="./resources/component/swfupload/2.2.0.1/handlers.js"></script>
<script type="text/javascript">
var swfupload;
$(function(){
var settings = {
flash_url : "./resources/component/swfupload/2.2.0.1/swfupload.swf",
flash9_url : "./resources/component/swfupload/2.2.0.1/swfupload_fp9.swf",
upload_url: "swfupload.do",
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
cancelButtonId : "btnCancel",
progressTarget : "fsUploadProgress"
},
debug: false,

// Button settings
button_image_url: "./resources/component/swfupload/2.2.0.1/XPButtonUploadText_61x22.png",
button_width: "80",
button_height: "22",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">Add File</span>',
button_text_style: ".theFont { font-size: 12; }",
button_text_left_padding: 4,
button_text_top_padding: 3,

// The event handler functions are defined in handlers.js
swfupload_preload_handler : preLoad,
swfupload_load_failed_handler : loadFailed,
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,//select file error
file_dialog_complete_handler : fileDialogComplete,//after selecting file
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,//upload fail
upload_success_handler : uploadSuccess,//upload success
upload_complete_handler : uploadComplete,//file upload complete
queue_complete_handler : queueComplete // Queue plugin event
};
swfupload = new SWFUpload(settings);
});
</script>
</head>
<body>
<div><span id="attachment">file:</span></div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel" onclick="swfupload.cancelQueue();" disabled="disabled"/>
<span id="divStatus">files uploaded</span>
</div>
<div id="fsUploadProgress"></div>
</body>
</html>

The most import javascript files are
handlers.js
my file are very simple, I delete a lot of functions in previous example. I just want to verify the file uploading function.

At first, I want to response the client json format data in json reponse. But I got 406 error.
HTML 406 Not Acceptable error on upload

So I change the response to application-context/text/html, It is ok now.

This is the answer about this in official website:
A regular browser doing an upload will accept results in these types: (taken from
actual headers)
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

references:
http://www.iteye.com/topic/1123391
http://www.iteye.com/topic/1123990
http://code.google.com/p/swfupload/
http://demo.swfupload.org/v220/index.htm

https://github.com/lardawge/swfupload-rails-authentication/issues/1
http://code.google.com/p/activeupload/issues/detail?id=2

你可能感兴趣的:(swfupload)