google-drive-apigoogle-drive-picker

Google Picker not selecting by file extension


Given files in Drive with an (arbitrary) extension *.abc, this code...

gapi.load("picker", { "callback": function () {
    if (!picker) {
        var view = new google.picker.DocsView(google.picker.ViewId.DOCS);

        view.setMimeTypes("application/vnd.google.drive.ext-type.abc");

        view.setMode(google.picker.DocsViewMode.LIST);
        picker = new google.picker.PickerBuilder();
        picker.setTitle(TEXT.PICKER_PROMPT);
        picker.setAppId(CONST.APP_ID);
        picker.addView(view);
        picker.setOAuthToken(session.OAuthToken.access_token);
        picker.setCallback(pickerCallback);
        picker.setInitialView(view);
    };
    picker.build().setVisible(true);
));

...doesn't find any of the existing 'abc' files in drive. These files are of mime type text/xml, and the following line DOES find them:

view.setMimeTypes("text/xml");

Why doesn't the search by extension work?


Solution

  • For those finding this from Google, the question wasn't as daft as it sounded - there is a (pseudo) mime-type for each extension in the Drive world, but it's not usable in that way, at least not in the Picker.

    A workable (ie user-friendly) solution is to use a query on the view:

    view.setQuery("*.abc");
    

    For completeness:

    gapi.load("picker", { "callback": function () {
        if (!picker) {
            var view = new google.picker.DocsView(google.picker.ViewId.DOCS);
    
            view.setMimeTypes("text/xml");
            view.setMode(google.picker.DocsViewMode.LIST);
            view.setQuery("*.abc");
    
            picker = new google.picker.PickerBuilder();
            picker.setTitle(TEXT.PICKER_PROMPT);
            picker.setAppId(CONST.APP_ID);
            picker.addView(view);
            picker.setOAuthToken(session.OAuthToken.access_token);
            picker.setCallback(pickerCallback);
            picker.setInitialView(view);
        };
        picker.build().setVisible(true);
    ));