如何解决如何使用Node JS中的Google Drive从Google Api克隆文件夹结构并将其上传到Google存储桶?
enter code here
**大家好,
我在Google驱动器中有一个名为sample的根文件夹,并且在sample中有多个文件夹,例如s1,s2,s3等。在该文件夹中又有一些文件和文件夹,我正在尝试下载其中包含文件的相同文件夹结构到我的本地驱动器,然后使用Google驱动器API的(drive.files.list)在NODE JS中同时上传到Google存储桶。在下面的代码中,我递归调用相同的函数,它在根文件夹级别上传所有文件
任何人的帮助将非常感激
谢谢你
示例代码供参考
async function listDriveFiles(folder){
console.log("In listDriveFiles");
const drive = google.drive({ version: 'v3',auth: oauth2Client });
const drivefordownload = google.drive({ version: 'v3',auth: oauth2Client });
drive.files.list({
q: `'${folder.id}' in parents`,fields: 'nextPageToken,files(*)',},async (err,response) => {
if (err) {
console.log('3',err)
//done({ errors: err,statusCode: 500 })
}
if (response != undefined || response != null) {
const files = response.data.files;
if (files.length) {
console.log("files length:" + files.length)
files.map(async (file) => {
if (validMimeTypeList.indexOf(file.mimeType) > -1) {
try {
console.log("before download")
await downLoadRawSalesFiles(drivefordownload,folder.name,file);
}
catch (err) {
console.log("Errors from downloading",err);
}
}else if(file.mimeType == 'application/vnd.google-apps.folder'){
await listDriveFiles(file);
}
});
}
}
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。