function uploadGuideMedia(req, res, next) {
if (!req.file && !req.body.id) {
return res.status(401).send({
status: 401,
data: "Upload a file with 'file' key"
});
}
db.query('SELECT * from guide_media where _id = $1', [req.body.id], function(err, guide) {
if (err) return next(err);
if (guide.rows.length == 0) {
return res.status(404).send({
status: 404,
data: "Guide_media not found"
})
} else {
let name = req.file.path + path.extname(req.file.originalname);
fs.renameSync(req.file.path, name);
req.file.path = name;
var s3bucket = new AWS.S3({
params: {
Bucket: 'mapery-v2'
}
});
fs.readFile(req.file.path, function(err, lq_file) {
s3bucket.createBucket(function() {
var params = {
Key: 'upload-v2/' + req.file.originalname,
Body: lq_file,
ContentType: req.file.mimetype,
ACL: 'public-read'
};
s3bucket.upload(params, function(err, aws_images) {
fs.unlink(req.file.path, function(err) {
db.query('UPDATE guide_media SET image_path = $1 WHERE _id = $2 RETURNING *', [aws_images.Location, req.body.id], function(err, guide_res) {
if (err) return next(err);
return res.status(200).send({
status: 'success',
data: guide_res.rows
});
});
});
})
})
})
}
});
}

答案 0 :(得分:1)
部分上传并不意味着您的文件将以多个部分存储在S3上。如果有效负载足够大,则SDK会同时上载多个部分的文件,以便在其中一个部分失败时可以部分重试上载。默认情况下,SDK使用5MB的partSize。您可以使用以下代码将partSize设置为10 MB。
var params = {Bucket: 'bucket', Key: 'key', Body: stream};
var options = {partSize: 10 * 1024 * 1024, queueSize: 1};
s3.upload(params, options, function(err, data) {
console.log(err, data);
});
编辑:链接到上传方法的文档。 http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property