// 文件上传// file_picker_types: 'file image media', // 指定允许上传的类型
file_picker_types:'file',// 指定允许上传的类型
file_picker_callback:function(callback, value, meta){
console.log(meta.filetype)console.log(343434)// // 要先模拟出一个input用于上传本地文件var input = document.createElement('input')input.setAttribute('type','file')// 你可以给input加accept属性来限制上传的文件类型// 例如:input.setAttribute('accept', '.jpg,.png')input.setAttribute('accept','.doc,.docx,.ppt,.pptx,.pdf,.xlsx')input.click()input.onchange=function(){
var file =this.files[0]console.log(this.files)console.log(file)console.log(file.name)// 下方被注释掉的是官方的一个例子// 放到下面给大家参考var reader =newFileReader()reader.onload=function(){
console.log(window.tinymce)// Note: Now we need to register the blob in TinyMCEs image blob// registry. In the next release this part hopefully won't be// necessary, as we are looking to handle it internally.var id ='blobid'+(newDate()).getTime()var blobCache = window.tinymce.activeEditor.editorUpload.blobCachevar base64 = reader.result.split(',')[1]var blobInfo = blobCache.create(id, file, base64)console.log(id)console.log(file)console.log(base64)console.log(file.name)console.log(blobInfo)console.log(blobInfo.blobUri())blobCache.add(blobInfo)// call the callback and populate the Title field with the file namecallback(blobInfo.blobUri(),{
text: file.name, title: file.name })}reader.readAsDataURL(file)}}