SwfUpload(1)swf multiple files uploading example

SwfUpload(1)swfmultiplefilesuploadingexample

swfUploadneedflashplayer.Itisgoodandeasytouse.

Myactionisasfollow:

@RequestMapping(value="/swfupload.do",method=RequestMethod.POST)

publicvoidswfupload(

@RequestParam(value="fileName",required=false)StringfileName,

@RequestParam(value="Filedata")MultipartFilefile,

HttpServletResponseresponse)throwsIOException{

logger.info("swforginalfilename="+file.getOriginalFilename()

+"filename="+fileName);

PrintWriterout=response.getWriter();

response.setContentType("text/html;charset=UTF-8");

response.setCharacterEncoding("UTF-8");

out.write("{success:true}");

out.close();

}

Myexampleisineasytalkerproject.

Thehtmlpagewillbeasfollow:

<html>

<head>

<title>SWFUploadDemo</title>

<linkrel="stylesheet"type="text/css"href="./resources/component/swfupload/2.2.0.1/default.css">

<scripttype="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<scripttype="text/javascript"src="./resources/component/swfupload/2.2.0.1/swfupload.js"></script>

<scripttype="text/javascript"src="./resources/component/swfupload/2.2.0.1/swfupload.queue.js"></script>

<scripttype="text/javascript"src="./resources/component/swfupload/2.2.0.1/fileprogress.js"></script>

<scripttype="text/javascript"src="./resources/component/swfupload/2.2.0.1/handlers.js"></script>

<scripttype="text/javascript">

varswfupload;

$(function(){

varsettings={

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:"100MB",

file_types:"*.*",

file_types_description:"AllFiles",

file_upload_limit:100,

file_queue_limit:0,

custom_settings:{

cancelButtonId:"btnCancel",

progressTarget:"fsUploadProgress"

},

debug:false,

//Buttonsettings

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:'<spanclass="theFont">AddFile</span>',

button_text_style:".theFont{font-size:12;}",

button_text_left_padding:4,

button_text_top_padding:3,

//Theeventhandlerfunctionsaredefinedinhandlers.js

swfupload_preload_handler:preLoad,

swfupload_load_failed_handler:loadFailed,

file_queued_handler:fileQueued,

file_queue_error_handler:fileQueueError,//selectfileerror

file_dialog_complete_handler:fileDialogComplete,//afterselectingfile

upload_start_handler:uploadStart,

upload_progress_handler:uploadProgress,

upload_error_handler:uploadError,//uploadfail

upload_success_handler:uploadSuccess,//uploadsuccess

upload_complete_handler:uploadComplete,//fileuploadcomplete

queue_complete_handler:queueComplete//Queuepluginevent

};

swfupload=newSWFUpload(settings);

});

</script>

</head>

<body>

<div><spanid="attachment">file:</span></div>

<div>

<spanid="spanButtonPlaceHolder"></span>

<inputid="btnCancel"type="button"value="Cancel"onclick="swfupload.cancelQueue();"disabled="disabled"/>

<spanid="divStatus">filesuploaded</span>

</div>

<divid="fsUploadProgress"></div>

</body>

</html>

Themostimportjavascriptfilesare

handlers.js

myfileareverysimple,Ideletealotoffunctionsinpreviousexample.Ijustwanttoverifythefileuploadingfunction.

Atfirst,Iwanttoresponsetheclientjsonformatdatainjsonreponse.ButIgot406error.

HTML406NotAcceptableerroronupload

SoIchangetheresponsetoapplication-context/text/html,Itisoknow.

Thisistheansweraboutthisinofficialwebsite:

Aregularbrowserdoinganuploadwillacceptresultsinthesetypes:(takenfrom

actualheaders)

text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

references:

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

相关推荐