generateShareLink method
Generates a shareable link for the file or directory at the path
.
Implementation
@override
Future<Uri?> generateShareLink(String path) {
return _executeRequest(() async {
final drive.File? file = await _getFileByPath(path);
if (file == null || file.id == null) {
return null;
}
// Create a permission to make the file accessible to anyone with the link.
final permission = drive.Permission()
..type = 'anyone'
..role = 'writer'; // or 'reader'
await driveApi.permissions.create(permission, file.id!, $fields: 'id');
// Retrieve the file metadata again to get the shareable link.
final fileMetadata = await driveApi.files
.get(file.id!, $fields: 'id, name, webViewLink') as drive.File;
if (fileMetadata.webViewLink == null) {
return null;
}
return Uri.parse(fileMetadata.webViewLink!);
});
}