gpt4 book ai didi

javascript - 如何阻止 Google Drive Picker UI 在选择特定文件后自动关闭?

转载 作者:行者123 更新时间:2023-12-03 00:55:38 29 4
gpt4 key购买 nike

默认情况下,如果我选择任何文件(csv、文本或 xls),Google 选择器会自动关闭。我希望它仅在扩展名是 csv 格式时才关闭。

请建议我需要在代码中进行哪些更改。

function pickerCallback(data) {
var url = 'nothing';
var file_Id = '';
var fileType = '';
if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
console.log(doc);
url = doc[google.picker.Document.URL];
file_Id = doc.id;
fileType = doc.mimeType;
if (fileType != "text/csv") {
alert("Error: Selected item is not CSV file");
// Google Picker closes automatically - Problem
// Restrict Google Picker from closing here
} else {
// Google Picker closes automatically - OK
downloadfile(file_Id); // function to perform on fetched file
}
}
var message = 'You picked: ' + url + ' having File Id: ' + file_Id;
console.log(message);
}

最佳答案

Picker API 具有指定可选 MIME 类型的方法。

PickerBuilder.setSelectableMimeTypes(string)

Set the list of MIME types which will be selectable. Use commas to separate MIME types if more than one is required.

https://developers.google.com/picker/docs/reference#PickerBuilder

示例

const view = new window.google.picker.DocsView();
const picker = new window.google.picker.PickerBuilder()
.addView(view)
.setSelectableMimeTypes('text/csv')
.setCallback(pickerCallback)
.build();
<小时/>

您可以选择限制应显示的 MIME 类型,以便用户只能看到 text/csv 文件。

View.setMimeTypes(string)

For views listing documents, set the MIME types which will be included in the view. Use commas to separate MIME types if more than one is required.

https://developers.google.com/picker/docs/reference#View

示例

const view = new window.google.picker.DocsView().setMimeTypes('text/csv');
const picker = new window.google.picker.PickerBuilder()
.addView(view)
.setCallback(pickerCallback)
.build();

关于javascript - 如何阻止 Google Drive Picker UI 在选择特定文件后自动关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52854709/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com