在我的 Web 应用程序中,照片被发送到 Azure 容器。问题是随机许多图像落入容器中,大小为 0 字节,因此无法使用。我已经查看了 azure linux 服务器,我注意到 Web 应用程序总是很好地发送照片。因为我暂时保留它们并将它们保留在正确的尺寸上。问题是当我发送它们时,它会发送一些 0 字节。
当我在本地测试照片或在 heroku 等其他平台上尝试时,系统会正确发送照片。我不明白为什么只在 Azure 中会导致此问题。
这是我的代码,但我再说一遍,在本地和其他平台中,即使使用 azure 容器也能很好地工作。我认为这是 azure 中 Web 应用程序的配置。但我不知道。
let almacenamiento = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads')
},
filename: function (req, file, cb) {
cb(null,Date.now() + '-' + file.originalname);
}
});
let upload = multer({ storage: almacenamiento,
fileFilter: function (req, file, cb) {
let ext = path.extname(file.originalname);
console.log(ext);
const regex = /(.JPEG|.jpeg|.png|.PNG|.jpg|.JPG)+/g;
if (!ext.match(regex)) {
return cb(new Error('El archivo debe ser una imagen!'))
}
cb(null, true)
},
limits: { fileSize: 5*1024*1024 }
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function create (req, res) {
blobService.createBlockBlobFromLocalFile(container, req.file.filename, req.file.path, function(error, result, response) {
ReceptionFile
.forge({
reception_file_url: result.name,
reception_file_comment: req.body.comentario,
file_type_id: req.body.idreferencia,
reception_id: req.body.recepcion
})
.save(null,{method: 'insert'})
.then(function(archivo) {
fs.unlink(path.resolve('./', 'uploads',archivo.attributes.reception_file_url), (err) => {
if (err) throw err;
console.log('successfully deleted /uploads/'+archivo.attributes.reception_file_url);
res.json({error: false, data: archivo.toJSON()});
});
}).catch(function(error){
console.log(error);
res.status(500).json({error: true, data: {message: error.message}});
});
});
};
router.post('/',upload.single('imagen'), create);
请确保未重写 Azure 上的连接字符串/应用设置,下面是 [参考] 的参考链接[1]
https://azure.microsoft.com/en-us/blog/windows-azure-web-sites-how-application-strings-and-connection-strings-work/