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
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.
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");
}
}
}
}
Any idea, please?
Thanks
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
{ [StorageAccount("blobConnectionString")] public class ViwerBlob
{
}
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