Example #1
0
        /**
         * Removes the to be deleted games image from the blob storage to conserve storage room
         */
        private async Task DeleteGameBlobImage(string imageUri)
        {
            var blobStorageContainer = _uploadService.GetGameImagesBlobContainer(AzureBlobStorageConnection);
            // Service client is used to get the reference because we have the Uri of the image not its name within the
            // container
            var blobImage = await blobStorageContainer.ServiceClient.GetBlobReferenceFromServerAsync(new Uri(imageUri));

            await blobImage.DeleteAsync();
        }
Example #2
0
        private async Task UploadGameImageAsync(NewGameModel model)
        {
            var game      = _game.GetById(model.Id);
            var container = _uploadService.GetGameImagesBlobContainer(_azureBlobStorageConnection);

            var contentDisposition = ContentDispositionHeaderValue.Parse(model.ImageUpload.ContentDisposition);
            var fileName           = contentDisposition.FileName.Trim('"');

            // Replace it with gameId to save space in Azure blob
            // As the file with the same name will overrite the old file.
            var fileExtension  = fileName.Substring(fileName.LastIndexOf('.'));
            var gameIdFileName = String.Concat(model.Id, fileExtension);

            var blockBlob = container.GetBlockBlobReference(gameIdFileName);

            await blockBlob.UploadFromStreamAsync(model.ImageUpload.OpenReadStream());

            await _game.SetGameImageAsync(game, blockBlob.Uri);
        }