我需要将文件从SFTP上传到S3存储桶。 我正在使用aws-sdk,定义了存储桶S3,然后上传了一个Stream。 问题是存储桶中的文件仅占开始8 MB的128 KB。
我想念什么吗?
我认为问题在于上载方法不会通过整个流,而是在128 KB的第一个“步骤”处停止。 也许某些“等待”输入错误?
export const saveFileToS3 = (stream: any, filePath : string) => {
return new Promise<string>(async (resolve: Function, reject: Function) => {
try {
const fileName = filePath.split('/')[3];
const s3 = new AWS.S3({
endpoint: 's3-eu-central-1.amazonaws.com',
signatureVersion: 'v4',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
});
let params = {
Bucket: process.env.S3_BUCKET_NAME,
Key: process.env.S3_PATH + fileName,
Body: stream
};
var options = {
partSize: 1500 * 1024 * 1024,
queueSize: 100
};
await s3.upload(params, options, function(s3Err, data) {
if (s3Err) throw s3Err
console.log(`File uploaded successfully at ${data.Location}`)
});
resolve(params);
} catch (error) {
reject(error);
}
});
};
export const getFileFromFtp = (filePath: string, ftpConf: Appp.FTPConf) => {
return new Promise<Stream>(async (resolve, reject) => {
logger.info(`getFileFromFtp - file path: ${filePath}`);
let client: SFTP;
try {
client = new SFTP();
const msg = await client.connect(ftpConf);
logger.info(`ftp client connected to ${ftpConf.host}`, msg);
const stream: Stream = await client.get(filePath);
client.end();
resolve(stream);
} catch (error) {
logger.error("error: " + error.message);
client && client.end();
reject(error);
}
});
};
我希望s3.upload上传所有流。