Beispiel #1
0
        public async Task <AnimalImage> UploadImage2([FromBody] AnimalImage animalImage)
        {
            try
            {
                var key = await _kv.GetKeyByName("WebSiteKey");

                CloudBlobClient    blobClient = BlobStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer container  = blobClient.GetContainerReference(BlobStorageContainerName);
                await container.CreateIfNotExistsAsync();

                animalImage.Id        = Guid.NewGuid().ToString().ToLowerInvariant();
                animalImage.ImageName = animalImage.ImageName;
                animalImage.ImageBlob = $"{animalImage.Id}/{animalImage.ImageName}";

                // This call creates a local CloudBlobContainer object, but does not make a network call
                // to the Azure Storage Service. The container on the service that this object represents may
                // or may not exist at this point. If it does exist, the properties will not yet have been
                // popluated on this object.
                CloudBlockBlob blockblob = container.GetBlockBlobReference(animalImage.ImageBlob);
                animalImage.UploadBlobSASUrl = Utils.GenerateWriteSasUrl(blockblob);

                // upload data to Cosmos DB
                await CosmosDBClient.UpsertDocumentAsync(CosmosDBCollectionUri, animalImage);

                //return blob url for uploading image
                return(animalImage);
            }
            catch (Exception ex)
            {
                // TODO: need better exception handling
                Trace.TraceError(ex.ToString());
                throw;
            }
        }
Beispiel #2
0
        // Initialize controller with depenedncy injection -  kvInstance singleton
        public StorageController(IKeyVaultAccessModel kvInstance)
        {
            _kv = kvInstance;

            BlobStorageCS = _kv.GetKeyByName("BlobStorageCS").Result.Value;
            CosmosDBKey   = _kv.GetKeyByName("CosmosDBKey").Result.Value;

            BlobStorageAccount    = CloudStorageAccount.Parse(BlobStorageCS);
            CosmosDBClient        = new DocumentClient(new Uri(CosmosDBUrl), CosmosDBKey);
            CosmosDBCollectionUri = UriFactory.CreateDocumentCollectionUri(CosmosDBName, CosmosDBCollectionName);
        }
        // Initialize controller with depenedncy injection -  kvInstance singleton
        public PredictionController(IKeyVaultAccessModel kvInstance)
        {
            _kv = kvInstance;

            predictionKey = _kv.GetKeyByName("CustomVisionPredictionKey").Result.Value;
        }
Beispiel #4
0
        public async Task <SecretBundle> GetKeyByName([FromRoute] string keyname)
        {
            var keyResponse = await _kv.GetKeyByName(keyname);

            return(keyResponse);
        }