I am using the Dropbox HTTP API, the AWS SDK for Node, and request-promise-native to download a PDF file from a Dropbox folder and immediately upload it to S3. This code is running in 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)
})
The Dropbox response's headers have the expected Content-Length and a Content-Disposition set to "attachment," which I am changing in the S3 put operation.
The resulting file on S3 is almost twice as large and cannot be opened by any PDF readers.
What am I missing?