Ejemplo n.º 1
0
        public async Task <IActionResult> UploadProfileImage(IFormFile file)
        {
            var userId = _userManager.GetUserId(User);

            //Connect to an Azure Storage Account Container
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");

            //Get Blob Storage
            var container = _uploadService.GetCloudBlobContainer(connectionString, "profile-images");

            //Parse the Content Disposition response header
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

            //Grab the filename
            var filename = contentDisposition.FileName.Trim('"');

            //Get a reference to a Block Blob
            var blockBlob = container.GetBlockBlobReference(filename);

            // On that block blob, Upload our file < --- fie Uploaded to the cloud
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            //Set the User's profile image to the URL
            await _userService.SetProfileImage(userId, blockBlob.Uri);

            //Redirect to the user's profile page
            return(RedirectToAction("Detail", "Profile", new { id = userId }));
        }
Ejemplo n.º 2
0
        private CloudBlockBlob UploadForumImage(IFormFile file)
        {
            //Connect to an Azure Storage Account Container
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");

            //Get Blob Storage
            var container = _uploadService.GetCloudBlobContainer(connectionString, "forum-images");

            //Parse the Content Disposition response header
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

            //Grab the filename
            var filename = contentDisposition.FileName.Trim('"');

            //Get a reference to a Block Blob
            var blockBlob = container.GetBlockBlobReference(filename);

            // On that block blob, Upload our file < --- fie Uploaded to the cloud
            blockBlob.UploadFromStreamAsync(file.OpenReadStream()).Wait();

            return(blockBlob);
        }