I am using TinyMCE in a project and want the user to select and upload file to the server using its default Insert/Edit Link window
The following code works fine for images but I am not sure how can this be handled in case of inserting a file for the link.
tinymce.init({
selector: "#uploadElementDiv",
plugins: [
"link image"
],
toolbar: "link unlink image",
image_advtab: true,
file_picker_types: 'file image',
file_picker_callback: function(callback, value, meta) {
if (meta.filetype == 'image') {
$('#upload').trigger('click');
$('#upload').on('change', function() {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(e) {
callback(e.target.result, {
alt: ''
});
};
reader.readAsDataURL(file);
});
}
if (meta.filetype == 'file') {
//some code here
}
}
}
<iframe id="uploadElementDiv" contenteditable="true" style="width:100%;border:none;height:100%;margin-top:10px;" ></iframe>
<input name="image" type="file" id="upload" class="hidden" onchange="">