-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
IMI can pull objects directly from a Google Drive with the following caveats/notes:
- The URI must be constructed using an API key to provide a direct download link, since shareable link points to a viewer, not the object.
- Files must be shared correctly.
- Google Team Drive does not allow sharing on folder level, only on a file by file basis.
If it's useful, below is a Google Code snippet intended to be run in a Google Sheet that will search through a GDrive folder and generate download links which the IMI can use to grab the objects. Commented out is also a line that will change permissions one at a time, only necessary for Team Drive (Insert obvious scary language about allowing that level of access to a script). Changing permissions, even via the API, can take a long time especially on a directory with a large number of files in it. It's better to change permissions on the folder level when possible (eg not in Team Drive).
function listFilesInFolder(folderName) {
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Required', 'Enter Folder ID', ui.ButtonSet.OK_CANCEL);
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["Name", "File-Id"]);
var folder = DriveApp.getFolderById(response.getResponseText());
var contents = folder.getFiles();
var cnt = 0;
var file;
while (contents.hasNext()) {
var file = contents.next();
cnt++;
// file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
// Replace {GOOGLEAPIKEY} in the following line with your api key.
// Instructions for getting API key: https://support.google.com/googleapi/answer/6158862?hl=en
var fileURL = "https://www.googleapis.com/drive/v3/files/" + file.getId() + "/?key={GOOGLEAPIKEY}&alt=media";
data = [
file.getName(),
fileURL,
];
sheet.appendRow(data);
};
};
'''
Metadata
Metadata
Assignees
Labels
No labels