我正在使用Dropbox HTTP API,AWS SDK for Node和request-promise-native从Dropbox文件夹下载PDF文件并立即将其上传到S3。此代码在AWS Lambda中运行:
const rp = require('request-promise-native')
const getOptions = {
url: 'https://content.dropboxapi.com/2/files/download',
method: 'GET',
headers: {
'Authorization': `Bearer ${settings.DROPBOX_TOKEN}`,
'Dropbox-API-Arg': JSON.stringify({ path: event.path })
},
gzip: true,
resolveWithFullResponse: true
}
rp(getOptions)
.on('error', callback)
.then((response) => {
const putOptions = {
ACL: 'public-read',
Bucket: 'mybucket',
Key: common.dropboxToS3Path(event.path),
Body: new Buffer(response.body),
ContentDisposition: `inline; filename=\"${path.basename(event.path)}\"`,
ContentEncoding: 'utf-8',
ContentLength: response.headers['content-length'],
ContentType: 'application/pdf'
}
s3.putObject(putOptions, function (err, data) {
callback(err, data)
})
})
.catch((err) => {
callback(err)
})
Dropbox响应的标题具有预期的Content-Length和Content-Disposition设置为“attachment”,我将在S3 put操作中更改。
S3上生成的文件几乎是原来的两倍,任何PDF阅读器都无法打开。
我错过了什么?