简体   繁体   English

带有Node.js googleapis包的Google Drive SDK引发错误:文件中包含0个mime部分的无效多部分请求

[英]Google Drive SDK with Node.js googleapis package throws Error: Invalid multipart request with 0 mime parts on files.create

I'm trying to upload a file to Google Drive using their Api and Nodejs. 我正在尝试使用其Api和Nodejs将文件上传到Google云端硬盘。 I've successfully run the quickstart code found here: https://developers.google.com/drive/v3/web/quickstart/nodejs 我已经成功运行了以下快速入门代码: https : //developers.google.com/drive/v3/web/quickstart/nodejs

I replaced the metadata.readonly scope in the example source with https://www.googleapis.com/auth/drive and replaced the call to listFiles() with one I created, createFile() 我将示例源中的metadata.readonly范围替换为https://www.googleapis.com/auth/drive ,并将对listFiles()的调用替换为我创建的一个,即createFile()

function createFile(auth) {
    var service = google.drive('v3');
    service.files.create({
        auth: auth,
        resource: {
            name: 'test'
        },
        media: {
            mimeType: 'plain/text',
            body: 'Hello drive'
        },
        fields: 'id'
    }, function (err, response) {
        if (err) {
            console.log(err);
            return;
        }
        console.log('Resource created successfully: ' + JSON.stringify(response));
    });
}

The response keeps coming back with en error: Error: Invalid multipart request with 0 mime parts. 响应不断返回并显示以下错误: Error: Invalid multipart request with 0 mime parts.

Would appreciate if anyone has some insight as to what is going wrong. 如果有人对出了什么问题有真知灼见,将不胜感激。 Thanks! 谢谢!

Update: Downgrading from googleapis 25 to 24 seems to have resolved the issue. 更新:从googleapis 25降级到24似乎已经解决了该问题。

Maintainer of the library here. 图书馆的维护者在这里。 Problems like this tend to pop up if you are trying to install your own version of google-auth-library alongside of googleapis . 如果您尝试将自己的google-auth-librarygoogleapis一起安装,则会弹出类似这样的问题。 googleapis comes with a compatible version of google-auth-library . googleapis带有google-auth-library的兼容版本。 Please make sure you remove google-auth-library from your package.json, and use google.auth.OAuth2 to get a reference to your auth object. 请确保您从package.json中删除google-auth-library ,并使用google.auth.OAuth2获取对您的auth对象的引用。

Can you give this a try, and let me know if it works with version 27? 您可以尝试一下,让我知道它是否适用于版本27?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复Mime零件错误为0的无效零件请求 - How to fix Invalid multipart request with 0 mime parts error 如何使用带有googleapis官方模块的node.js创建Google云端硬盘文件夹 - How to create a Google Drive folder using node.js with googleapis official module Node.js Google 云端硬盘 API 错误 getaddrinfo EAI_AGAIN www.googleapis.com - Node.js Google Drive API error getaddrinfo EAI_AGAIN www.googleapis.com Node.js:添加googleapis程序包后部署到Heroku时出错 - Node.js: Error deploying to Heroku when added googleapis package 如何在 Node.js 中使用 googleapis 创建新的 Google 电子表格 - How to Create New Google Spreadsheet Using googleapis in Node.js 雅典娜Node.js AWS开发工具包-任何请求都将引发InvalidRequestException - Athena Node.js AWS SDK - Any request throws InvalidRequestException 使用Google Drive API和Node.js创建Google文档 - Create a Google Document with Google Drive API and Node.js Node.js-通过请求从Google云端硬盘下载文件 - Node.js - Download File from Google Drive via request Excel 使用Node.js SDK上传到Dropbox的文件无效 - Excel files uploaded to Dropbox using Node.js SDK are invalid 无法使用node.js和OAuth令牌在Google云端硬盘中创建文件 - Unable to create file in Google Drive with node.js and OAuth tokens
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM