3

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?

4

2 回答 2

5

对于那些从 Google 发现这个问题的人来说,这个问题并不像听起来那么愚蠢——Drive 世界中的每个扩展都有一个(伪)mime 类型,但它不能以这种方式使用,至少在 Picker 中不能使用。

一个可行的(即用户友好的)解决方案是在视图上使用查询:

view.setQuery("*.abc");

为了完整性:

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);
));
于 2016-04-08T15:19:14.780 回答
2

添加到 HeyHeyJC 的答案中||,如果要使用多个文件扩展名,可以使用双管道 () 分隔每个文件扩展名。

例如,view.setQuery("*.abc || *.def || *.ghi");

于 2021-04-23T07:17:23.107 回答