function prepareUpload(uploadFold,size){ uploader=$("#uploadify").uploadify({ 'auto' : false, 'swf' : getRootPath()+'/resources/js/upload/uploadify.swf', 'uploader' : getRootPath()+'/html/upload', 'formData' : {"fold":uploadFold}, 'queueID' : 'fileQueue',//与下面的id对应 'queueSizeLimit' : size, 'buttonImage' : getRootPath()+'/resources/imgs/addFile.png', 'buttonText' : '添加课件', 'fileTypeDesc' : 'rar文件或zip文件', 'fileTypeExts' : '*.mp4;*.zip;*.flv;*.xls;*.doc;*.xlsx;*.f4v;', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc 'multi' : true, 'cancel' : getRootPath()+'/resources/js/upload/uploadify-cancel.png',
根据'uploader' : getRootPath()+'/html/upload', 来上传hmtl包:
/** * 上传Html包 * * @param Filedata * @param request * @param fold * @return * @throws IOException */ @RequestMapping(value = "/upload", method = RequestMethod.POST, produces = "text/html;charset=UTF-8") @ResponseBody public String upload(MultipartFile Filedata, HttpServletRequest request, String fold) throws IOException { String path = File.separator + Constants.COURSEWARE_DIR + File.separator + fold; String fileName = Filedata.getOriginalFilename(); path += File.separator + fileName; String realPath = handleContextRealPath(path, request); FileUtils.copyInputStreamToFile(Filedata.getInputStream(), new File(realPath)); /* * 如果为压缩文件,将其解压 */ String suffix = fileName.substring(fileName.lastIndexOf(".")); String destPath = realPath.substring(0, realPath.lastIndexOf(File.separator)); if (suffix.toLowerCase().contains("zip")) { Ziper.unZip(new File(realPath), new File(destPath)); } return path; }
读取:
/** * 查看资源 * * @param id * @return */ @RequestMapping("/{id}/show") public String show(@PathVariable Long id, Model model, HttpServletRequest request, RedirectAttributes redirectAttrs,@RequestParam(value = "page", required = false, defaultValue = "1" )int page) { /* * 根据目标Html包的类型返回合适的资源定位 */ Html html = this.htmlService.findById(id); String resourceUri = null; //resourceUri = html.getDirPath(); File indexPage = findDefaultPage(request, html); if(null!=indexPage && indexPage.exists()){ String pagePath=indexPage.getPath(); pagePath=CommonUtils.removeRepeat(pagePath, handleContextRealPath("", request)); resourceUri=pagePath; } /* * 无法访问进行提示 */ if (null == resourceUri) { sendErrorMessageWhenRedirect(redirectAttrs, "resource.invaild"); return "redirect:"+request.getHeader("Referer"); } model.addAttribute("type", html.getType()); model.addAttribute("resourceUri", resourceUri.replaceAll("\\\\", "/")); model.addAttribute("html", html); return "html/show"; } /** * @param request * @param html * @return */ private File findDefaultPage(HttpServletRequest request, Html html) { String dirPath = html.getDirPath(); dirPath = dirPath.substring(0, dirPath.lastIndexOf(File.separator)); String rootPath = handleContextRealPath(dirPath, request); File rootDir = new File(rootPath); Deque<File> files = new ArrayDeque<File>(); files.push(rootDir); File indexPage = FileUtil.findFile(files, ImmutableList.of("index.htm", "index.html","login.html")); return indexPage; }