2

I am using the wp.media frame uploader in my plugin to upload files. It works perfectly as it should except one problem. When I upload file (using upload button, or drag and drop) it uploads the file and displays its information in sidebar menu, but doesn't display thumbnail of attachment. Its a kind of annoying problem because first its a default behaviour on wp.media and second same implementation is working fine on different plugin. Has anyone come across this problem..

Code I used is:

    var alex_doc_uploader = $thisButton.data('file_frame');
    if (alex_doc_uploader) {
        alex_doc_uploader.open();
        return;
    }

    // Create the media frame.
    alex_doc_uploader = wp.media.frames.file_frame = wp.media({
        title: "Select Documents",
        button: {
            text: "Select Documents"
        },
        library : {
          type:   accepted_mime_types
        },
        multiple: true  // Set to true to allow multiple files to be selected
    });

    $thisButton.data('file_frame', alex_doc_uploader);

And when i upload a file, enter image description here

The result I get is enter image description here

But what should happen is enter image description here

user98239820
  • 1,411
  • 2
  • 16
  • 30
  • https://vrajeshdave.wordpress.com/2015/06/05/how-to-use-default-media-upload-in-plugin-page/ – vrajesh Jun 16 '15 at 06:27
  • @vrajesh : I am following the same concept and it works but the problem is not displaying thumbnail when uploaded. Its a default behaviour as I understand. So I wonder what is that I am missing to wp.media is not functioning as it should. – user98239820 Jun 16 '15 at 06:50
  • hey you are uploading document file ....how can we create thumbnail of document file...? – vrajesh Jun 16 '15 at 06:52
  • By thumbnail I mean Icon of document.. Like the one that is on screen.. When I reopen the media uploader, I can see that document.. but not right away when I upload.. – user98239820 Jun 16 '15 at 06:55
  • u mean when reopen the media upload all file you had uploaded would be selected? – vrajesh Jun 16 '15 at 07:04
  • @vrajesh I have added more detail.. – user98239820 Jun 16 '15 at 07:19
  • please check http://stackoverflow.com/questions/14187611/display-media-uploader-in-own-plugin-on-wordpress-3-5 – vrajesh Jun 16 '15 at 07:27
  • you need to add function file_frame.on('select', function() { – vrajesh Jun 16 '15 at 07:27

1 Answers1

0

Figured out the problem.. It was a bug on wordpress till 4.2.2. Wordpress can't support multiple mimetypes provided as type of wp.media. It does support to filter out the content displayed but can't load on screen if uploaded. Here is the issue created on wordpress

Media Upload mimeType validation bug

My patch

hopefully it will be solved in 4.2.3 or 4.3. Or you can do patch with those patches

user98239820
  • 1,411
  • 2
  • 16
  • 30