我正在编写一个Apps脚本,通过UrlFetchApp获取文件并将其写入Google云端硬盘。
段:
var response = UrlFetchApp.fetch(url, options);
Logger.log("Response code: " + response.getResponseCode());
var blob = response.getBlob();
mimeType = response.getHeaders()['Content-type'];
Logger.log("MIMEType: " + mimeType);
Logger.log("Response size (Content-Length): " + response.getHeaders()['Content-Length']);
Logger.log("Blob size: " + blob.getBytes().length);
newFile = {
'mimeType' : mimeType,
'title' : 'test.txt',
'parents' : [{
'kind' : 'drive#parentReference',
'id' : driveFolderId
}]
};
file = Drive.Files.insert(newFile, blob);
Logger.log("Drive file size: " + file.fileSize);
在以下日志消息中运行以上结果:
[14-09-07 17:29:01:619 PDT] Response code: 200
[14-09-07 17:29:01:620 PDT] MIMEType: application/octet-stream
[14-09-07 17:29:01:620 PDT] Response size (Content-Length): 5
[14-09-07 17:29:01:621 PDT] Blob size: 5
[14-09-07 17:29:02:537 PDT] Drive file size: 0
导航到云端硬盘确认该文件存在,位于右侧文件夹中,但大小为0.
似乎blob没有通过insert()方法将其放入文件中。我尝试使用没有数据的insert()然后使用blob更新(),结果相同。