SpringMVC整合Ueditor报错:未找到上传数据

重写BinaryUploader,升级common-io 2.8

 package com.baidu.ueditor.upload;
import java.io.File;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;

 import javax.servlet.http.HttpServletRequest;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

 
 import com.baidu.ueditor.PathFormat;
import com.baidu.ueditor.define.AppInfo;
 import com.baidu.ueditor.define.BaseState;
 import com.baidu.ueditor.define.FileType;
 import com.baidu.ueditor.define.State;
 public class BinaryUploader
 {
	public static final State save(HttpServletRequest request,  Map<String, Object> conf) {
	    try {
	        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
	        MultipartFile multipartFile = multipartRequest.getFile(conf.get("fieldName").toString());
	
	        String savePath = (String) conf.get("savePath");
	        String originFileName = multipartFile.getOriginalFilename();
	        String suffix = FileType.getSuffixByFilename(originFileName);
	
	        originFileName = originFileName.substring(0,originFileName.length() - suffix.length());
	        savePath = savePath + suffix;
	
	        long maxSize = ((Long) conf.get("maxSize")).longValue();
	
	        if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
	            return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
	        }
	        savePath = PathFormat.parse(savePath, originFileName);
	        String physicalPath = (String)conf.get("physicsPath");
	        if (physicalPath != null && !"".equals(physicalPath)) {
	        	physicalPath = physicalPath + savePath;
	        } else {
	        	physicalPath = conf.get("rootPath") + savePath;
	        } 
	        File targetFile = new File(physicalPath);
	        if(!targetFile.getParentFile().exists()){  
	            targetFile.getParentFile().mkdirs();  
	        }
	        //State storageState = StorageManager.saveFileByInputStream(multipartFile.getInputStream(),savePath, maxSize);
	        State storageState = StorageManager.saveFileByInputStream(multipartFile.getInputStream(),physicalPath, maxSize);
	        if (storageState.isSuccess()) {
	            storageState.putInfo("url", PathFormat.format(savePath));
	            storageState.putInfo("type", suffix);
	            storageState.putInfo("original", originFileName + suffix);
	        }
	        return storageState;
	
	    }catch (Exception e) {
	        e.printStackTrace();
	        System.out.println(e.getMessage());
	    }
	    return new BaseState(false, AppInfo.IO_ERROR);
	}
    private static boolean validType(String type, String[] allowTypes) {
    	List<String> list = Arrays.asList(allowTypes);
    	return list.contains(type);
    }
 }

 

//下面和这个问题无关,只是记录

package com.baidu.ueditor.spring;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 编辑器业务响应
 * @author wall
 * @date 2020-11-30
 */
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baidu.ueditor.ActionEnter;

@Controller
@RequestMapping("/ueditor/ueditor.do")
public class UeditorController {
	/**
	 * 读取配置
	 * @author wall
	 * @date 2020-11-30
	 */
	@RequestMapping(value = "action=*")
	@ResponseBody
	public void ueditorAction(HttpServletRequest request,HttpServletResponse response) {
		try {
			request.setCharacterEncoding( "utf-8" );
			response.setHeader("Content-Type" , "text/html");
			String rootPath =request.getServletContext().getRealPath( "/" );
			ActionEnter ae = new ActionEnter(request,rootPath);
			PrintWriter out = response.getWriter();
			out.write(ae.exec());
		} catch (IOException e) {
			e.printStackTrace();
		}
	} 
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值