【问题标题】:Images with 0 bytes in azure storage container blob天蓝色存储容器 blob 中具有 0 字节的图像
【发布时间】:2018-09-19 02:43:35
【问题描述】:

在我的 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);

【问题讨论】:

    标签: node.js azure azure-blob-storage


    【解决方案1】:

    确保您没有覆盖 Azure 上的连接字符串/应用设置,这里是您的 [参考][1] 的参考链接

    https://azure.microsoft.com/en-us/blog/windows-azure-web-sites-how-application-strings-and-connection-strings-work/

    猜你喜欢
    • 1970-01-01
    • 2021-07-26
    • 2022-01-08
    • 2015-12-04
    • 2014-09-30
    • 2015-09-09
    • 2022-08-02
    • 2019-08-18
    • 2019-08-11
    相关资源
    最近更新 更多