public static async Task <IActionResult> RunGetAllVideos( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "data/videos")] HttpRequest req, [Table(TableNames.RedirectSessions)] CloudTable redirectTable, ILogger log, ExecutionContext context) { dynamic[]? videoData = await GetVideo.All(redirectTable); if (videoData != null) { return(new OkObjectResult(videoData)); } else { return(new NotFoundResult()); } }
public static async void ProcessFileExports( [QueueTrigger(QueueNames.ProcessFileExports)] string processFileExportsQueue, [Table(TableNames.RedirectSessions)] CloudTable redirectTable, ILogger log, ExecutionContext context) { FileExportEntity queueFileExport = JsonConvert.DeserializeObject <FileExportEntity>(processFileExportsQueue); var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); Stream stream = new MemoryStream(); if (queueFileExport.SourceUrl.StartsWith("https://") || queueFileExport.SourceUrl.StartsWith("http://")) { var client = new HttpClient(); stream = await client.GetStreamAsync(queueFileExport.SourceUrl); } else { if (queueFileExport.SourceUrl == FileExportTypes.AllVideos) { dynamic[] data = await GetVideo.All(redirectTable); stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(JsonConvert.SerializeObject(data)); writer.Flush(); stream.Position = 0; } } // Create a BlobServiceClient object which will be used to create a container client BlobServiceClient blobServiceClient = new BlobServiceClient(config.GetValue <string>(queueFileExport.DestinationStorage)); // Create the container and return a container client object BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(queueFileExport.DestinationContainer); BlobClient blobClient = containerClient.GetBlobClient(queueFileExport.DestinationLocation); await blobClient.DeleteIfExistsAsync(); await blobClient.UploadAsync(stream); BlobHttpHeaders headers = new BlobHttpHeaders(); bool addHeaders = false; if (queueFileExport.DestinationLocation.ToLower().EndsWith(".json")) { headers.ContentType = "application/json"; addHeaders = true; } if (config.GetValue <string>("FILE_EXPORT_CACHE_CONTROL") != null) { headers.CacheControl = config.GetValue <string>("FILE_EXPORT_CACHE_CONTROL"); addHeaders = true; } if (addHeaders) { await blobClient.SetHttpHeadersAsync(headers); } // log.LogError($"URL lookup {queueFileExport.SourceUrl} failed with status code {getResponse.StatusCode}"); // throw new System.Exception($"URL lookup {queueFileExport.SourceUrl} failed with status code {getResponse.StatusCode}"); }