1 (edited by Orbitall 2016-02-18 15:27:22)

Topic: Problems programically adding mime_types

Im creating a file manager for my website and require to change the mime_types dependant on certain situations.

     //initilise plupload
    settings = 
    {   
        runtimes : 'html4,silverlight',
        url : 'php/function/upload.php',
        max_file_count: 20,
        resize : 
        {
            quality : 90,
            crop: true
        },
        filters : 
        {
            max_file_size : '1000mb',
            mime_types: []
        },
        rename: true,
        sortable: true,
        dragdrop: true,
        views: 
        {
            list: true,
            thumbs: true, 
            active: 'thumbs'
        }
    }

    $("#uploader").plupload(settings);

    //programically change url and mime_types settings.
    function setUploadOptions(dir)
    {
          var uploader = $("#uploader").plupload('getUploader');
          //this works
          uploader.settings.url = 'php/function/upload.php?location='+dir;
           //this does not work
           uploader.settings.filters.mime_types = [{title : "application/pdf", extensions : "pdf"}]; 
     } 

I managed to update the url, but accessing the mime_types in the same way causes this error:
TypeError: e.regexp is undefined - plupload.full.min.js:28:2925

Incase this was the issue I added custom moxie extensions before initilsing plupload (I still get same error), using:
mOxie.Mime.addMimeType("application/pdf,pdf");

- How can I  change (remove + add) the mime types settings in plupload after iniltilisation using js/jquery?

2 (edited by 5050 2016-06-12 18:23:26)

Re: Problems programically adding mime_types

I have exactly the same problem, even if I'm not using jquery.
I succeeded to add 2 variables to plupload and to update and use them according to the page using an unique js script file, but not mime_types...

I also tryed

uploader.settings.filters = {mime_types : [{title : "Archive", extensions : "zip"}]};

which give exactly the same error.

3 (edited by 5050 2016-06-12 21:10:28)

Re: Problems programically adding mime_types

Ok, after trying to analyse the source code in file plupload.dev.js, around line 1230 and a few tries, I've a start of answer:

When the list of mime-types is loaded, a regexp is built, which is used later. Loading a new list with "uploader.settings.filters.mime_types = xxx" does not work because the regexp remains empty. We must use :

uploader.setOption('filters', {mime_types:[{title : "Archive", extensions : "zip"}, {... etc ... }]} );

From my tries with a display of the mime-type with var_dump() before and after the call,  I found that setOptions can only ADD new mime-types to an empty list, or replace the items already in the list, starting by the first, without clearing the list before.
If the new list have less elements than the previous that was already loaded, old mime_type may remains.