【发布时间】:2018-10-12 10:26:33
【问题描述】:
我有一个需要来自 JSON 文件的训练数据的神经网络脚本,是否可以使用 Google Apps 脚本将 JSON 文件保存到 Google Drive?
【问题讨论】:
标签: json file google-apps-script
我有一个需要来自 JSON 文件的训练数据的神经网络脚本,是否可以使用 Google Apps 脚本将 JSON 文件保存到 Google Drive?
【问题讨论】:
标签: json file google-apps-script
您可以使用高级驱动器服务。在 Google Drive 中创建文件有 3 个选项。
目前,Apps Script 既有旧版代码编辑器,也有新版代码编辑器。在两个编辑器中启用高级驱动器服务是不同的。
旧版编辑器:
新编辑器:
过去,您还需要在 Google Cloud Platform 中启用 Drive API。但现在你有两个选择。
如果 Apps Script 项目将被公众使用,那么您应该创建一个“标准”Google Cloud 项目,并在 Google Cloud Platform 中启用 Google Drive API。
function saveAsJSON() {
var blob,file,fileSets,obj;
obj = {//Object literal for testing purposes
key:"value"
}
/**
* Creates a file in the users Google Drive
*/
fileSets = {
title: 'AAA_Test.json',
mimeType: 'application/json'
};
blob = Utilities.newBlob(JSON.stringify(obj), "application/vnd.google-apps.script+json");
file = Drive.Files.insert(fileSets, blob);
Logger.log('ID: %s, File size (bytes): %s, type: %s', file.id, file.fileSize, file.mimeType);
}
【讨论】:
application/vnd.google-apps.script+json? MimeType 没有这样的定义:developers.google.com/apps-script/reference/base/mime-type
Drive.Files.insert(filesets, blob); 和DriveApp.getRootFolder().createFile('AAA_Test.json', JSON.stringify(obj), MimeType.PLAIN_TEXT); 之间是否存在有意义的区别?如果/何时尝试读取文件的内容有区别吗?在我的测试中(乍一看),这些文件在形式和功能上看起来相同,除了一个例外:当单击 GDrive 中的文件时,“详细信息”窗格将显示前者的“类型:未知文件”和“类型:文本”为后者。
filesets mimetype 应该是 "text/plain" 或 MimeType.PLAIN_TEXT 例如:fileSets = {title: "AAA_Test.txt", mimeType: "text/plain"};