|
@@ -311,4 +311,90 @@ public class BosController {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 阿里云上传图片
|
|
|
+ * 公告内容上传图片
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param file
|
|
|
+ * @param multiRequest
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/uploadImg")
|
|
|
+ public void uploadImg(HttpServletRequest request, HttpServletResponse response, MultipartFile file, MultipartHttpServletRequest multiRequest) {
|
|
|
+ String DirectoryName = request.getParameter("storeAs");
|
|
|
+ String newName="";
|
|
|
+ String filepath = "";
|
|
|
+ try {
|
|
|
+
|
|
|
+ if("1".equals(uploadMode)){
|
|
|
+ try {
|
|
|
+ //MultipartFile转File
|
|
|
+ File srcFile = transformMultipartFile(file);
|
|
|
+ String path = directory+"/"+DirectoryName+datePath()+"/"+ System.currentTimeMillis()+srcFile.getName();
|
|
|
+ BOSClientUtil bosClientUtil = new BOSClientUtil();
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
+ String upload = bosClientUtil.upload(path, inputStream);
|
|
|
+ if(srcFile.exists()){
|
|
|
+ srcFile.delete();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ }
|
|
|
+ }else if("2".equals(uploadMode)){
|
|
|
+ LayFileJsonData data = new LayFileJsonData();
|
|
|
+ // 判断文件是否为空
|
|
|
+ Iterator<String> fileNames = multiRequest.getFileNames();
|
|
|
+ while(fileNames.hasNext()) {
|
|
|
+ //取得上传文件
|
|
|
+ file = multiRequest.getFile(fileNames.next());
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ // 文件保存路径
|
|
|
+ String realPath =directory.replace("/","")+"/"+DirectoryName+datePath()+"/"+ System.currentTimeMillis();
|
|
|
+ OSSClientUtil ossUtil = new OSSClientUtil();
|
|
|
+ newName = file.getOriginalFilename();
|
|
|
+
|
|
|
+ try {
|
|
|
+ ossUtil.uploadFile2OSS(file.getInputStream(),realPath,newName);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ filepath = Global.getAliDownloadUrl() + "/" + realPath + newName;
|
|
|
+
|
|
|
+ data.setName(file.getOriginalFilename());
|
|
|
+ data.setSrc(filepath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ try {
|
|
|
+ //MultipartFile转File
|
|
|
+ File srcFile = transformMultipartFile(file);
|
|
|
+ SftpClientUtil fileUploadUtil = new SftpClientUtil();
|
|
|
+ String uploadPath = "/" + DirectoryName + datePath();
|
|
|
+ String uploadFile = fileUploadUtil.uploadFile(uploadPath, srcFile, srcFile.getName());
|
|
|
+ if(srcFile.exists()){
|
|
|
+ srcFile.delete();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 结合ckeditor功能
|
|
|
+ // imageContextPath为图片在服务器地址,如upload/123.jpg,非绝对路径
|
|
|
+ OSSClientUtil ossUtil = new OSSClientUtil();
|
|
|
+ String imageContextPath =ossUtil.getFileTemporaryLookUrl(filepath);
|
|
|
+ response.setContentType("text/html;charset=UTF-8");
|
|
|
+ String callback = request.getParameter("CKEditorFuncNum");
|
|
|
+ PrintWriter out = response.getWriter();
|
|
|
+ out.println("<script type=\"text/javascript\">");
|
|
|
+ out.println("window.parent.CKEDITOR.tools.callFunction(" + callback + ",'" + imageContextPath + "',''" + ")");
|
|
|
+ out.println("</script>");
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ } catch (IllegalStateException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|