Beispiel #1
0
        public static async Task RunAsync([ServiceBusTrigger("analyze", Connection = "ServiceBus")] string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
            var targetContainer = "review";

            try
            {
                if (await IsAllowed(myQueueItem))
                {
                    targetContainer = "accepted";
                }
            }
            catch (Exception ex)
            {
                log.LogError($"Unable to add image to list. Caught {ex.GetType().FullName}: {ex.Message}");
            }

            string storageConnectionString = Environment.GetEnvironmentVariable("Storage");

            // Retrieve the storage account
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
            // Create the blob client, for use in obtaining references to blob storage containers
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            await BlobHelpers.CopyFile(blobClient, "input", targetContainer, Path.GetFileName(myQueueItem));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "thumbnails")] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var config = new ConfigurationBuilder()
                         .SetBasePath(context.FunctionAppDirectory)
                         .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                         .AddEnvironmentVariables()
                         .Build();

            string storageConnectionString = config["Storage"];

            // Retrieve the storage account
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
            // Create the blob client, for use in obtaining references to blob storage containers
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            // Get container reference
            var container = blobClient.GetContainerReference("thumbs");

            var files = await BlobHelpers.BlobsList(container);

            var data = JsonConvert.SerializeObject(files);

            return(new OkObjectResult(data));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "photo")] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var config = new ConfigurationBuilder()
                         .SetBasePath(context.FunctionAppDirectory)
                         .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                         .AddEnvironmentVariables()
                         .Build();

            string storageConnectionString = config["Storage"];

            try
            {
                var    file       = req.Form.Files[0];
                string folderName = "input";

                var url = "";

                if (file.Length > 0)
                {
                    var ext = Path.GetExtension(file.FileName).ToLower().Replace(".", "");
                    if (!FileTypes.Contains(ext))
                    {
                        return(new BadRequestObjectResult("Valid filetypes are only: " + FileTypesJson));
                    }

                    // Retrieve the storage account
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
                    // Create the blob client, for use in obtaining references to blob storage containers
                    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                    // Get container reference
                    var container = blobClient.GetContainerReference(folderName);

                    url = await BlobHelpers.UploadFileToBlob(file, container);

                    //url += BlobHelpers.GetBlobSasToken(container, Path.GetFileName(url), SharedAccessBlobPermissions.Read);

                    await ServiceBusQueueHelpers.SendMessageAsync("analyze", url, config["ServiceBus"]);
                }

                return(new OkObjectResult("Upload Successful."));
            }
            catch (System.Exception ex)
            {
                return(new BadRequestObjectResult("Upload Failed: " + ex.Message));
            }
        }