ueditor 添加自定义上传接口

 1.从 http://ueditor.baidu.com/website/ 下载jsp版本
2.将下载的压缩文件解压,命名为ueditor,复制整个文件夹到项目中
3.在页面上新建一个textarea的标签
<textarea id="container" name="content" style="width: 100%; height: 350px; margin: 0 auto;"></textarea>
4.
    <!-- 配置文件 -->
    <script type="text/javascript" src="plugins/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="plugins/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container');
        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
        UE.Editor.prototype.getActionUrl = function(action) {
            if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
                return '<%=basePath%>app s/editUpload';
            } else if (action == 'uploadvideo') {
                return '<%=basePath%>app s/editUpload';
            } else {
                return this._bkGetActionUrl.call(this, action);
            }
        }
    </script>  

5.springmvc后台代码

    /**
     * 上传图片到OOS
     * 
     * @param file
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "/editUpload", method = RequestMethod.POST)
    @ResponseBody
    public UploaderParam editUpload(@RequestParam(value = "upfile", required = false) MultipartFile file) throws IOException {
        
        // 将MultipartFile转换成file
        CommonsMultipartFile cf = (CommonsMultipartFile) file;
        DiskFileItem fi = (DiskFileItem) cf.getFileItem();
        File f = fi.getStoreLocation();
        String prefix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);// 后缀名
        String key = "upload/" + UuidUtil.get32UUID() + "." + prefix;
        try {
            OOSUtils.upload2(f, key);
        } catch (Exception e) {
//            error = e.getMessage();
        }
        String url = " http://couponworld.oss-cn-shenzhen.aliyuncs.com/" + key;
        UploaderParam uploaderParam = new UploaderParam(file.getName(), file.getOriginalFilename(), file.getSize(),
                "SUCCESS", file.getContentType(), url, file.getOriginalFilename());
        return uploaderParam;
    }  


uploadParam实体类:
public class UploaderParam {
    private String name; // 通过upfile获取
    private String originalName; // 通过upfile获取
    private Long size; // 通过upfile获取
    private String state;// 成功必须为"SUCCESS"
    private String type; // 通过upfile获取
    private String url; // 图片回显url
    private String title;
    public UploaderParam() {
        super();
    }
    public UploaderParam(String name, String originalName, Long size, String state, String type, String url,
            String title) {
        super();
         this.name = name;
        this.originalName = originalName;
        this.size = size;
        this.state = state;
        this.type = type;
        this.url = url;
        this.title = title;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
         this.name = name;
    }
    public String getOriginalName() {
        return originalName;
    }
    public void setOriginalName(String originalName) {
        this.originalName = originalName;
    }
    public Long getSize() {
        return size;
    }
    public void setSize(Long size) {
        this.size = size;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
}   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值