Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion picker/code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ function showPicker() {
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, "Select a file");
}
// Ensure the Drive API is enabled.
if (!Drive) {
throw new Error('Please enable the Drive advanced service.');
}

/**
* Checks that the file can be accessed.
* @param {string} fileId The ID of the file.
* @return {Object} The file resource.
*/
function getFile(fileId) {
return Drive.Files.get(fileId, { fields: "*" });
return Drive.Files.get(fileId, {fields: '*'});
}

/**
Expand Down
19 changes: 17 additions & 2 deletions picker/dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,27 @@
}
}

/**
* @typedef {Object} PickerResponse
* @property {string} action
* @property {PickerDocument[]} docs
*/

/**
* @typedef {Object} PickerDocument
* @property {string} id
* @property {string} name
* @property {string} mimeType
* @property {string} url
* @property {string} lastEditedUtc
*/

/**
* A callback function that extracts the chosen document's metadata from the
* response object. For details on the response object, see
* https://developers.google.com/picker/reference/picker.responseobject
*
* @param {object} data The response object.
* @param {PickerResponse} data The response object.
*/
function pickerCallback(data) {
const action = data[google.picker.Response.ACTION];
Expand All @@ -128,7 +143,7 @@
/**
* Handles `"PICKED"` responsed from the Google Picker.
*
* @param {object} data The response object.
* @param {PickerResponse} data The response object.
*/
function handlePicked(data) {
const doc = data[google.picker.Response.DOCUMENTS][0];
Expand Down
Loading