const formData = req.file('image')
const options = {
url: 'myurl'',
method: 'POST',
formData : formData
}
request.post(options, async function(err,result,body){
if(err)
{
res.json({
success: false,
message: "There are some error occured in file upload"
});
}
else
{
res.json({success: true});
}
});
我正在尝试使用request.post上传图片,但不允许我上传图片,请指导如何修复
请指导
Edit1:
谢谢
答案 0 :(得分:0)
在ejs表单中使用enctype ='multipart / form-data'。
由于您是使用microservervice将图像从一个后端(example1.com)发送到另一个后端(example2.com)的,因此请先将该图像保存在第一个后端(example1.com)
然后将该图像路径(example1.com/images/img1.jpg)传递给发布请求。例如
postdata = { imageurl:'example1.com/images/img1.jpg', 图片尺寸:“ 1200”, }
只有example1.com能够访问您的本地图像路径(例如:c://temp/img1.jpg)。因此,您应该将该图像上传到服务器1(example1.com)
或者将图像转换为Blob类型并发送。这样,您无需将图像保存在server1(example1.com)中。