MyException - 我的异常网
当前位置:我的异常网» 操作系统 » 百度ueditor图片上传到OSS有关问题解决

香港六合彩今晚开奖结果:百度ueditor图片上传到OSS有关问题解决

香港六合彩现场直播 www.hppyv.com  网友分享于:2018-05-05  浏览:0次
百度ueditor图片上传到OSS问题解决
前端

 香港六合彩现场直播 www.hppyv.com UE.Editor.prototype._bkGetActionUrl=UE.Editor.prototype.getActionUrl;  
    UE.Editor.prototype.getActionUrl=function(action){  
        if (action == 'uploadimage' ||action== 'uploadscrawl' || action == 'uploadimage') {  
            return '<%=request.getContextPath()%>/totalmsg/upload';  
        }   else if(action == 'listimage'){  
            return this._bkGetActionUrl.call(this, action);  
        } else{  
            return this._bkGetActionUrl.call(this, action);  
        }  
    }  




//后端进行OSS保存

package com.oceano.modity.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.aliyun.oss.OSSClient;
import com.oceano.config.EnvironmentConfig;
import com.oceano.modity.util.ConstantUtil;

//ueditor图书文件上存

@Controller
@RequestMapping("/ueditorUpload")
public class ueditorUploadController {

    @Autowired
    EnvironmentConfig environmentConfig;

    private String randomFileName() {
	Random random = new Random();
	return System.currentTimeMillis() + random.nextInt(1000) + "";
    }

    @SuppressWarnings("unused")
    @RequestMapping(value = "/upload")
    @ResponseBody
    public Object upload(@RequestParam("upfile") MultipartFile file, HttpServletRequest request,
	    HttpServletResponse response) throws IOException {
	Map<String, Object> parm = new HashMap<>();
	// CommonsMultipartFile cf=(CommonsMultipartFile)file;
	// DiskFileItem fi = (DiskFileItem) cf.getFileItem();
	// InputStream fileContent = fi.getInputStream();
	// String fileName=fi.getName();
	// String suffix=fileName.substring(fileName.lastIndexOf("."));

	// 产品目录
	String uuid = request.getParameter("uuid");
	// 环境
	String environment = environmentConfig.getEnvironment();
	// 功能
	String function = request.getParameter("function");

	OSSClient ossClient = new OSSClient(ConstantUtil.END_POINT, ConstantUtil.ACCESS_ID, ConstantUtil.ACCESS_KEY);
	// while (iter.hasNext()) {
	// 取得上传文件
	// MultipartFile file = multiRequest.getFile(iter.next());
	System.out.println(file.getContentType());
	System.out.println(file.getOriginalFilename());

	// if(null == file){
	//
	// }

	if (null != file) {
	    try {
		String fileName = file.getOriginalFilename();
		String imageType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
		String randomName = randomFileName() + "." + imageType;

		ossClient.putObject(ConstantUtil.BUCKET, ConstantUtil.BUCKET_FILE + "ueditorUpload/" + environment + "/"
			+ function + "/" + uuid + "/" + randomName, file.getInputStream());
		String imageUrl = "//" + ConstantUtil.BUCKET + "." + ConstantUtil.END_POINT
			+ ConstantUtil.BUCKET_FILE + "ueditorUpload/" + environment + "/" + function + "/" + uuid + "/"
			+ randomName;

		parm.put("state", "SUCCESS");
		parm.put("url", imageUrl);
		return parm;
	    } catch (Exception e) {
		e.printStackTrace();
		parm.put("status", 500);
		return parm;
	    } finally {
		ossClient.shutdown();
	    }
	} else {
	    parm.put("state", "SUCCESS");
	    return parm;
	}
    }

}



https://blog.csdn.net/qq_39402549/article/details/78608711

文章评论

软件开发程序错误异常香港六合彩现场直播Copyright © 2009-2015 MyException 版权所有
台湾百万彩官方网站! 河北体育彩票中心 大乐透走势图图 超级大乐透17043期选号 哪款彩票软件最好 2019斯诺克世锦标赛 香港赛马会平码网 喜乐彩500期走势图 上海快3一定牛走势图带连线 北京时时彩彩赛车开奖记录 稳赚包平特肖二期开一期 斗地主游戏大厅手机版礼包 2019排列五走势图 北京赛车pk10直播视频直播 禁波+杀五行