我想将图像发送到另一台服务器及其工作。但是问题是,当我尝试发送一个图像并且将尺寸大于2mb的图像发送时,可以执行发布,但该图像在另一台服务器上不存在。我不知道我犯了什么错误。希望可以帮助我解决这个问题。预先谢谢你。
var fs = require("fs");
var router = require("express").Router();
var multer = require("multer");
var request = require("request");
var storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, "picture/");
},
filename: function(req, file, cb) {
cb(null, file.originalname);
}
});
var upload = multer({ storage });
function sendImageToAnotherServer(params,isAddImage,files) {
//var otherUrl = "http://localhost/upload_file/";
let Status = {
status: _const.MSG_STATUS_ERROR,
message: _const.MSG_STATUS_ERROR,
info: null
};
files.forEach(image => {
const formData = {
image: fs.createReadStream("picture/" + image.originalname)
};
request.post( { url: otherUrl, formData: formData }, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error("upload failed:", err);
}
console.log("Upload successful! Server responded with:", body);
}
);
});
}
在PHP Side上增加upload_max_filesize之后。可以将图像上传到另一台服务器(PHP Side)