google-apps-script - Google 脚本 - 解压缩 Mimetype 应用程序/x-zip
问题描述
我经常下载一个 .zip 文件(不是由我创建的),它是 Mimetype "application/x-zip",它没有被 Utilities.unzip(file) 处理,并出现以下错误。我希望有人能够帮助我解析这个文件。
谢谢。
var thisFile = DriveApp.getFileById(newestFileId);
//Successfully gets the file as verified by other processes
var thisBlob = thisFile.getBlob();
var createMe = thisFolder.createFile("workingb.zip", thisBlob, "application/zip");
//Creates a 4-byte file with the text "Blob"
var createMe = thisFolder.createFile("workingf.zip", thisFile, "application/zip");
//Creates an 11-byte file with the text the same as the filename.ext
Logger.log(thisFile.getMimeType());
// "application/x-zip"
var test1 = thisFile.getAs("application/zip");
//Exception: Converting from application/x-zip to application/zip is not supported
var thisUnzip = Utilities.unzip(test1);
//Exception: Invalid argument
解决方案
这个改装怎么样?我认为您的情况有两种模式。
模式一:
如果文件名的扩展名是.zip
,那么这个修改怎么样?
var thisFile = DriveApp.getFileById(newestFileId);
var thisBlob = thisFile.getBlob();
var convertedBlob = thisBlob.setContentTypeFromExtension();
var thisUnzip = Utilities.unzip(convertedBlob);
模式二:
如果文件名没有扩展名或扩展名是除 之外的值.zip
,那么这个修改怎么样?
var thisFile = DriveApp.getFileById(newestFileId);
var thisBlob = thisFile.getBlob();
var convertedBlob = thisBlob.setContentType("application/zip");
var thisUnzip = Utilities.unzip(convertedBlob);
参考:
如果这些不是你想要的,我很抱歉。
推荐阅读
- java - 无法实例化类 - Selenium WebDriver (TestNG)
- git - 在未来几个月从存储库中移动所有提交
- java - Java/Jackson:使用 HashMap 将 JSON 反序列化为类
- cython - 如果 PyObject 是 Cython 函数,则检查 C
- arrays - 由数组定义的打字稿类型
- javascript - 使用 AngularJS 和 javascript 显示/隐藏数组中的元素
- r - R:计算一系列列中列名中的文本不匹配
- swift - 核心数据实体中不同属性值的值总和
- sql - 与不是主键的标识列的关系
- php - Wordpress 小部件作为 div