Reputation: 175
I read a pdf file via sFTP
and then upload it to S3. When I download the file from S3 and open it in a pdf viewer, it's a blank document. The file size on sFTP
is 40kb, but on S3, it's 80kb.
This is how I download via sftp:
sftp.readFile(filePath, 'utf-8', (error, content) => {
if (error) throw error;
conn.end();
resolve(content);
});
And this is how I upload to S3:
const uploadParams = {
Bucket: bucket, Key: '', Body: '', ContentType: 'application/pdf'
};
uploadParams.Body = content;
uploadParams.Key = fileAttributes.s3Location;
logger.debug('Uploading to S3', uploadParams);
// call S3 to retrieve upload file to specified bucket
try {
const stored = await s3.putObject(uploadParams).promise();
logger.info('Upload Success', stored);
} catch (err) {
logger.error('S3 upload error', err);
throw err;
}
Perhaps something is wrong with the encoding being used?
Upvotes: 1
Views: 1587
Reputation: 175
The solution was to remove the encoding. It seems to be auto detected correctly and the file contents are visible in S3. Changed to this:
sftp.readFile(filePath, (error, buffer) => {
if (error) throw error;
conn.end();
resolve(buffer);
});
Upvotes: 1