コード例 #1
0
        /**
         * Removes the to be deleted users profile image from the blob storage to conserve storage room
         */
        private async Task DeleteUserBlobImage(string imageUrl)
        {
            var blobStorageContainer = _uploadService.GetStorageContainer(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(imageUrl));

            await blobImage.DeleteAsync();
        }
コード例 #2
0
ファイル: ForumController.cs プロジェクト: optmzer/ForumApp
        private CloudBlockBlob UploadForumImage(IFormFile file)
        {
            var container          = _uploadService.GetStorageContainer(AzureBlobStorageConnection);
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var fileName           = contentDisposition.FileName.Trim('"');
            var blockBlob          = container.GetBlockBlobReference(fileName);

            // Do not need await modifier in this case
            blockBlob.UploadFromStreamAsync(file.OpenReadStream());
            return(blockBlob);
        }
コード例 #3
0
        public async Task <IActionResult> UploadUserProfileImage(IFormFile file)
        {
            var userId             = _userManager.GetUserId(User);
            var container          = _uploadService.GetStorageContainer(AzureBlobStorageConnection);
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var fileName           = contentDisposition.FileName.Trim('"');
            var blockBlob          = container.GetBlockBlobReference(fileName);

            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            await _userService.SetProfileImageAsync(userId, blockBlob.Uri);

            return(RedirectToAction("UserDetails", "UserProfile", new { userId }));
        }
コード例 #4
0
ファイル: Index.cshtml.cs プロジェクト: optmzer/Scoreboards
        /*
         * Uploads User Profile image to Azure Blob storage
         */

        private async Task UploadUserProfileImage(IFormFile file)
        {
            var userId    = _userManager.GetUserId(User);
            var container = _uploadService.GetStorageContainer(AzureBlobStorageConnection);
            // Get file name
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var fileName           = contentDisposition.FileName.Trim('"');

            // Replace it with userId 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 userIdFileName = String.Concat(userId, fileExtension);

            var blockBlob = container.GetBlockBlobReference(userIdFileName);

            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            await _applicationUserService.SetProfileImageAsync(userId, blockBlob.Uri);
        }