@RequestMapping(value = "/upload", method = RequestMethod.POST) public String upload(HttpServletRequest request, HttpServletResponse response) { try { String referer = request.getHeader("referer"); Pattern p = Pattern.compile("([a-z]*:(//[^/?#]+)?)?", Pattern.CASE_INSENSITIVE); Matcher mathcer = p.matcher(referer); if (mathcer.find()) { String callBackPath = mathcer.group();// 请求来源a.com MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile imgFile = multipartRequest.getFile("fileupload");//k4中fileupload //JsonObject json =自己的处理imgFile // 同域时直接返回json.toString()就可以无需redirect String url = "redirect:" + callBackPath + "/kindeditor/plugins/image/redirect.html?s=" + json.toString() + "#" + json.toString(); logger.info(String.format("upload success url:%s", url)); return url; } else { logger.info("upload referer not find"); } } catch (Exception e) { logger.error("upload error", e); } return null; }
upload success url:http://a.com/kindeditor/plugins/image/redirect.html?s={"error":0,"url":"http://upload.268xue.com/upload/sns/temp/20140510/1399706737140139370.jpg"}#{"error":0,"url":"http://upload.268xue.com/upload/sns/temp/20140510/1399706737140139370.jpg"}
var uploadbutton = KindEditor.uploadbutton({ button : KindEditor("fileupload")[0], fieldName : "fileupload", url : "http://upload.268xue.com/upload", afterUpload : function(data) { if (data.error == 0) { //data.url 处理 } else { alert("error"); } }, afterError : function(str) { //alert('error: ' + str); } }); uploadbutton.fileBox.change(function(e) { uploadbutton.submit(); });
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ie shit shit</title> <script type="text/javascript"> //获取url參数 function getParameter(val) { var uri = window.location.search; var re = new RegExp("" + val + "=([^&?]*)", "ig"); return ((uri.match(re)) ?
(uri.match(re)[0].substr(val.length + 1)) : null); } var upload_callback = function(){ var data=getParameter("s"); var location_hash=location.hash; //ie6取不到hash??
?用那个方式取?暂使用url传參数s if(location_hash!=null && location_hash!="" && location_hash){ var data = location.hash ? location.hash.substring(1) : ''; document.getElementsByTagName("body")[0].innerHTML = '<pre>' + data + '</pre>'; }else{ var data=getParameter("s"); document.getElementsByTagName("body")[0].innerHTML = '<pre>' + data + '</pre>'; } }; </script> </head> <body onload="upload_callback();"> </body> </html>
如:http://a.com/kindeditor/plugins/image/redirect.html?s=%7B%22error%22:0,%22url%22:%22/upload/demo_web/temp/20140510/1399698690364609649.jpg%22%7D#%7B%22error%22:0,%22url%22:%22/upload/demo_web/temp/20140510/1399698690364609649.jpg%22%7D
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。