0
votes

In my web application, photos are sent to an azure container. The problem is that randomly many images fall into the container with a size of 0 bytes, therefore unusable. I have reviewed the azure linux server and I have noticed that the web application always sends the photos well. Because I keep them temporarily and keep them with the correct sizes. The problem is when I send them, which sends some with 0 bytes.

The system sends the photos correctly when I test it locally or when I try it on other platforms like heroku. I do not understand why only in Azure causes this problem.

This is my code, but I repeat, locally and in other platforms it works well even using the azure container. I think it's configuration of the web app within azure. But I do not know.

    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);
1

1 Answers

0
votes

Make sure you are not overriding the Connection String/App setting on Azure, here is the reference link for your [reference][1]

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