
<link href="uploadify.css" rel="stylesheet"><script src="jquery.uploadify.min.js"></script>
<input type="hidden" id="filepathInput" /><input type="file" id="btnUploadify" name="uploadify" /><div id="show_back"></div>
function initUploadify() {$("#btnUploadify").uploadify({height: 30,swf: "uploadify.swf",cancelImage: "uploadify-cancel.png",uploader: ‘common/op/uploadFileForMedia.shtml?type=video‘,fileTypeDesc: ‘视频类型‘,fileTypeExts: ‘*.mp4‘,width: 100,multi: false,fileSizeLimit : ‘10MB‘, //设置单个文件大小限制method: ‘post‘,fileObjName: ‘uploadify‘,buttonText: "选择文件",onUploadSuccess: function (file, data, response) {//上传成功if (response) {var dataJson = eval("(" + data + ")");$("#filepathInput").val(dataJson.filePath);var html = ‘<video controls=controls autoplay=autoplay> ‘+‘<source src="‘+ dataJson.basepath + "\/" + dataJson.filename+‘" type="video/mp4" />‘+‘</video>‘;$("#show_back").html(html);}},onUploadError : function(file,errorCode,errorMsg,errorString,swfuploadifyQueue) {},auto: true});}
public class FileUploadAction extends BaseAction {private File uploadify;private String uploadifyFileName;public String uploadFile() throws Exception {map = new HashMap<String, Object>();// 上传完后文件存放位置String savePath = getRealPath() + "upload";System.out.println(savePath);String newsuffix = "";String current = UUID.randomUUID().toString();if ((uploadifyFileName != null) && (uploadifyFileName.length() > 0)) {int dot = uploadifyFileName.lastIndexOf(".");if ((dot > -1) && (dot < (uploadifyFileName.length() - 1))) {newsuffix = uploadifyFileName.substring(dot + 1);}}FileInputStream fis = null;FileOutputStream fos = null;try {fis = new FileInputStream(uploadify);String serPath = savePath + File.separatorChar + current + "."+ newsuffix;fos = new FileOutputStream(serPath);IOUtils.copy(fis, fos);map.put("filename", current + "." + newsuffix);map.put("basepath", "upload/");} catch (Exception e) {e.printStackTrace();} finally {if (fos != null) {fos.flush();fos.close();}if (fis != null) {fis.close();}}return "toResult";}}
原文:http://blog.csdn.net/u013628152/article/details/46483215