[英]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-library
与googleapis
一起安装,则会弹出类似这样的问题。 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.