错误:写完后

时间:2016-03-27 17:08:42

标签: javascript node.js google-drive-api google-api-nodejs-client

使用google-api-nodejs-client的drive.files.update方法时,我收到以下错误

Error: write after end
at ClientRequest.OutgoingMessage.write (_http_outgoing.js:422:15)
at Request.write (/Users/user/GitHub/project/node_modules/google-auth-library/node_modules/request/request.js:1362:25)
at ReadStream.ondata (_stream_readable.js:528:20)
at emitOne (events.js:77:13)
at ReadStream.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at ReadStream.Readable.push (_stream_readable.js:110:10)
at onread (fs.js:1832:12)
at FSReqWrap.wrapper [as oncomplete] (fs.js:614:17)

只需使用fs.createReadStream()

即可获得此功能
global.drive.files.update({
    fileId: 'IHU0...',
    media: {
        body: fs.createReadStream('file.js')
    },
}, function(err, response) {
    if (err) {
        return console.error(`Error occurred: ${err.stack}`);
    }
    console.log(`UPDATED, response: ${JSON.stringify(response)}`);
});

0 个答案:

没有答案