I wanted to add a trigger button to upload image as a data. So I added the following piece of code
<textarea id="test"></textarea>
<input name="image" type="file" id="test-upload" class="hidden" onchange="">
tinymce.init({
selector: '#test',
...,
paste_data_images: true,
image_advtab: true,
file_picker_callback: function(callback, value, meta) {
if (meta.filetype == 'image') {
jQuery('#test-upload').trigger('click');
jQuery('#test-upload').on('change', function() {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(e: any) {
callback(e.target.result, {
alt: ''
});
};
reader.readAsDataURL(file);
});
}
},
...
});
This is working as expected. I am getting a file picker for the image as below
But I am also getting this file picker when I try to add link as well.
How to avoid this?
Add the
file_picker_types
setting to your configuration and specify where the picker should be used.https://www.tinymce.com/docs/configure/file-image-upload/#file_picker_types
The default is:
...but you can change it to:
...at which point the picker won't appear for files (links).