我有一个内置了angular和node js的应用程序。我正在使用“ multter”将我的“角度形式”的图像上传到s3存储桶。现在,我启用了“同步”选项,该选项可以将所有数据同步到包含来自外部api的图像的表单,但是在数据同步的情况下,我将图像作为链接而不是文件接收。有什么方法可以从链接下载图像并将其保存在我的s3存储桶中?
马尔特
const s3 = new aws.S3();
const upload = multer({
storage: multerS3({
s3: s3,
acl: 'public-read',
bucket: 'elasticbeanstalk-eu-west-x-xxxxxxxxxxxx',
metadata: function (req, file, cb) {
cb(null, {fieldName: file.originalname});
},
key: function (req, file, cb) {
cb(null, Date.now().toString())
}
})
})
路线
router.post("", extractFile,
(req, res, next) => {
const movie = new Movie({
movieName: req.body.movieName,
movieDirector: req.body.movieDirector,
movieReleaseDate: req.body.movieReleaseDate,
movieDescription: req.body.movieDescription,
movieImg: image,
});
movie.save().then(createdMovie => {
res.status(201).json({
message: createdMovie.movieName + " added successfully",
movie: {createdMovie}
});
})
.catch(error => {
res.status(500).json({
message: "Adding movie failed!"
});
});
}
);