Node.js 将NodeJS管道数据发送至AWS S3类型错误:dest.on不是一个函数
请告诉我为什么我的代码使用PassThrough抛出管道错误:Node.js 将NodeJS管道数据发送至AWS S3类型错误:dest.on不是一个函数,node.js,amazon-s3,pipe,Node.js,Amazon S3,Pipe,请告诉我为什么我的代码使用PassThrough抛出管道错误:TypeError:dest.on不是函数 我最初认为这是因为我没有返回PassThrough,正如另一篇文章中所述 现在我不太确定了?提前谢谢 const { google } = require('googleapis') const auth = require('./googleOAuth') const aws = require('aws-sdk') const fs = require('fs') const stre
TypeError:dest.on不是函数
我最初认为这是因为我没有返回PassThrough,正如另一篇文章中所述
现在我不太确定了?提前谢谢
const { google } = require('googleapis')
const auth = require('./googleOAuth')
const aws = require('aws-sdk')
const fs = require('fs')
const stream = require('stream')
// AWS S3 bucket name to upload to
const awsBucketName = 'my-backup'
// get AWS keys stored in local file and pass through to AWS auth
const getAWSKeys = async () => {
const awsKeys = await auth.read('./cred/awskeys.json').then(result => {return result})
aws.config.update({
accessKeyId: awsKeys.keys.aws_access_key_id,
secretAccessKey: awsKeys.keys.aws_secret_access_key
})
}
// upload a file to AWS S3 by passing the file stream from getGFileContent into the 'body' parameter of the upload
const s3Upload = async () => {
await getAWSKeys()
let pass = new stream.PassThrough()
let params = {
Bucket: awsBucketName, // bucket-name
Key: 'filePath.jpg', // file will be saved as bucket-name/[uniquekey.csv]
Body: pass // file data passed through stream
}
new aws.S3().upload(params).promise()
.then(() => console.log(`Successfully uploaded data to bucket`))
.catch( err => console.log(`Error, unable to upload to S3: ${err}`))
return pass
}
// download gFile, non google docs files. Downloaded as a stream of data and pipped into the awsUpload function
const getGFileContent = async () => {
const gKeys = await auth.get()
const drive = google.drive({version: 'v3', auth: gKeys})
let params = {fileId: '1bNr_ZM90fM0EnPcFPfdd2LnB7Z2Tts3LiQ', mimeType: "image/jpeg", alt: 'media'}
return drive.files.get(params, {responseType: 'stream'})
.then(res => {
return new Promise((resolve, reject) => {
res.data
.on('end', () => {resolve()})
.on('error', err => {reject(`Error downloading Google docs file: ${err}`)})
.pipe(s3Upload())
})
})
}
getGFileContent()
我被困在同一个问题中,你得到答案了吗?@ashutosh不幸没有:(实际上s3不支持管道文件夹,我想这是我的问题。在你的情况下,我认为Body得到的是文件夹而不是文件。我被困在同一个问题中,你得到答案了吗?@ashutosh不幸没有:(实际上s3不支持管道文件夹,我认为这是我的问题。在你的情况下,我认为Body得到的是文件夹而不是文件。