Blob Trigger Azure Function doesn't run when i publish it

1.5k Views Asked by At

I have an Azure function that every time a blob is added to a container in my storage account, it performs a series of operations with it and then sends a message.

Everything works correctly in my local Visual Studio solution using the connection to the real Azure storage account

local

but when I publish everything seems to be going well however when I add blobs to the container there is no invocation of my function and I don't know what could be failing or missing.

function app

test

container

This is the code that works fine in local

public static class InsertarConcursosEnBBDD
{
    [FunctionName("InsertarConcursosEnBBDD")]
    public static void Run(
      [BlobTrigger("test/{name}", Connection = "AzureWebJobsStorage")] Stream blobStream,
      [SendGrid(ApiKey = "SendGridApiKey")] ICollector<SendGridMessage> sender,
      string name, 
      ILogger log)
    {
              if (name.ToLower().EndsWith("xlsx"))
              {
          log.LogInformation($"Blob trigger function Processed blob\n Name:{name}");

          ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

          DestriparExcel destripaExcel = new DestriparExcel();

          var _insertarDatos = new InsertarDatos();

          var emailPrincipal = "[email protected]";
          var emailCopia = "[email protected]";

          var message = new SendGridMessage();
          message.From = new EmailAddress(Environment.GetEnvironmentVariable("EmailSender"));
          message.AddTo(emailPrincipal);
          message.AddCc(emailCopia);



          using (ExcelPackage package = new ExcelPackage(blobStream))
          {
            ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault();

            List<ConcursoExcel> listaConcursosExcel = destripaExcel.ImportarDatos(name, worksheet);

            List<Concurso> listaConcursosAInsertar = _insertarDatos.TransformarConcursosExcelAConcursosBoletus(listaConcursosExcel);

            var registrosAñadidos = _insertarDatos.InsertarConcursos(listaConcursosAInsertar);

            message.Subject = "Concursos diarios";
            message.HtmlContent = $"{registrosAñadidos} Concursos añadidos correctamente a la BBDD correspondientes al fichero {name}";

            sender.Add(message);

            log.LogInformation($"Se han añadido {registrosAñadidos} concursos a la  base de datos");
          }

        }
              else
              {
          log.LogInformation($"El fichero {name} no tiene extension xlsx");
        }


    }
  }
}

app settings

executions

Any idea, please?

Thanks

1

There are 1 best solutions below

0
On

i was stuck in the same problem, the solution i found is:

enter image description here

look at how my settings.json is made and how my settings in azure are made:

enter image description here

here is my code

namespace FunctionAppBlob

{ [StorageAccount("blobConnectionString")] public class ViwerBlob
{

    [FunctionName("Function1")]
    public void Run(
        [BlobTrigger("blob-prueba/{name}.png")] Stream myBlob,
        [Blob("blob-prueba/{name}.jpeg", FileAccess.Write)] Stream renamed,
        string name, ILogger log)
    {
        try
        {
            myBlob.CopyTo(renamed);
            moid(name);
            log.LogInformation("Nombre de archivo agregado correctamente");
        }
        catch (Exception ex)
        {
            log?.LogError("archivo imposible de procesar");
        }
        
    }     
        
    private void moid(string name)
    {
        try
        {                
            var conn = Environment.GetEnvironmentVariable("blobConnectionString");               
            BlobClient blobFile = new BlobClient(conn, "blob-prueba", name+".png");             
            blobFile.DeleteIfExists();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
       
    }
   

}

}


In my json settings I added the string connection, i had to put it there to provide it in VS and run the app locally and it worked, once in Azure I modified the configuration(azureFuncion->Configuration) by entering a new app settings and putting in the same name and value as settings.json. I did that and like wish in heaven it works perfectly..

my app is crap haha, I just want to change extension and deleting the file..

first time answering here, I really sorry for the mess