사용자가 Google Drive에서 파일이나 폴더를 선택할 수 있도록 하려면 Google 선택 도구를 사용하도록 SelectionInput 위젯을 구성하면 됩니다. 이 가이드에서는 부가기능의 구성 카드에서 Google Picker를 설정하는 방법을 설명합니다.
Google Picker 구성
Google Drive에서 파일 또는 폴더를 선택할 수 있도록 선택 입력 위젯을 사용 설정하려면 CommonDataSource 및 DriveDataSourceSpec로 PlatformDataSource를 구성해야 합니다.
CommonDataSource를DRIVE로 설정합니다. 이렇게 하면 Google Drive가 선택 입력의 소스로 지정됩니다.- (선택사항) 사용자가 선택할 수 있는 파일 형식을 지정하려면
DriveDataSourceSpec를 추가합니다. 다음 항목 유형 중 하나 이상을 지정할 수 있습니다.DOCUMENTSSPREADSHEETSPRESENTATIONSPDFSFORMSFOLDERS
예: 스프레드시트 및 PDF 선택
다음 예에서는 사용자가 Google Drive에서 여러 스프레드시트 또는 PDF 파일을 선택할 수 있는 구성 카드를 빌드합니다. 단계가 실행되면 선택한 항목의 파일 ID가 출력 변수로 반환됩니다.
JSON
{
"timeZone": "America/Los_Angeles",
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"addOns": {
"common": {
"name": "Drive Picker Demo",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
"useLocaleFromApp": true
},
"flows": {
"workflowElements": [
{
"id": "file_selection",
"state": "ACTIVE",
"name": "File selection",
"workflowAction": {
"inputs": [
{
"id": "drive_picker_1",
"description": "Choose a file from Google Drive",
"dataType": {
"basicType": "STRING"
}
}
],
"outputs": [
{
"id": "fileId",
"description": "The id of the selected file",
"cardinality": "SINGLE",
"dataType": {
"basicType": "STRING"
}
}
],
"onConfigFunction": "onConfig",
"onExecuteFunction": "onExecute"
}
}
]
}
}
}
Apps Script
/**
* Returns a configuration card for the step.
* This card includes a selection input widget configured as a Google Picker
* that lets users select spreadsheets and PDFs.
*/
function onConfig() {
// Allows users to select either spreadsheets or PDFs
const driveSpec = CardService.newDriveDataSourceSpec()
.addItemType(
CardService.DriveItemType.SPREADSHEETS
)
.addItemType(
CardService.DriveItemType.PDFS
);
const platformSource = CardService.newPlatformDataSource()
.setCommonDataSource(
CardService.CommonDataSource.DRIVE
)
.setDriveDataSourceSpec(driveSpec);
const selectionInput =
CardService.newSelectionInput()
.setFieldName("drive_picker_1")
.setPlatformDataSource(platformSource)
.setTitle("Drive Picker")
.setType(
CardService.SelectionInputType.MULTI_SELECT
);
var sectionBuilder =
CardService.newCardSection()
.addWidget(selectionInput)
return CardService.newCardBuilder()
.addSection(sectionBuilder)
.build();
}
/**
* Executes when the step runs.
* This function retrieves the file ID of the item selected in the Google Picker
* and returns it as an output variable.
* @param {Object} event The event object passed by the Flows runtime.
* @return {Object} The output variables object.
*/
function onExecute(event) {
//Extract the selected file's ID during execution
console.log("eventObject: " + JSON.stringify(event));
var fileId = event.workflow.actionInvocation.inputs["drive_picker_1"].stringValues[0];
const variableData = AddOnsResponseService.newVariableData()
.addStringValue(fileId);
let textFormatElement = AddOnsResponseService.newTextFormatElement()
.setText("A file has been selected!");
let workflowTextFormat = AddOnsResponseService.newWorkflowTextFormat()
.addTextFormatElement(textFormatElement);
let workflowAction = AddOnsResponseService.newReturnOutputVariablesAction()
.addVariableData("fileId", variableData)
.setLog(workflowTextFormat);
let hostAppAction = AddOnsResponseService.newHostAppAction()
.setWorkflowAction(workflowAction);
return AddOnsResponseService.newRenderActionBuilder()
.setHostAppAction(hostAppAction)
.build();
}