几行代码让TinyMCE支持阿里云OSS

添加OSS SDK

OSS配置

//配置替换成你自己的
var client = new OSS({
    region : 'oss-cn-beijing',
    accessKeyId : '',
    accessKeySecret : '',
    bucket : ''
});

配置TinyMCE

tinymce.init({
...省略若干代码...
plugins: [
   'image'
],
toolbar1: "image",
images_upload_handler: function (blobInfo, success, failure) {
    var filename = blobInfo.filename();
    var index = filename.lastIndexOf(".");
    var suffix = filename.substring(index+1, filename.length);
    filename = md5(blobInfo.base64()) + '.' + suffix;
    client.multipartUpload(filename, blobInfo.blob()).then(function (result) {
        if(result.res.requestUrls) {
            success(result.res.requestUrls[0]);
        }
    }).catch(function (err) {
        console.log(err);
    });
},
...省略若干代码...
});

看看效果

你可能感兴趣的:(tinymce,oss,javascript)