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

            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");

            var container = _uploadService.GetBlobContainer(connectionString, "profile-images");

            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

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

            var blockBlob = container.GetBlockBlobReference(filename);

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

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

            return(RedirectToAction("Detail", "Profile", new { id = userId }));
            //connect to azure storage container
            //Get blob container

            //parse content dispostion response header

            //get reference to block blob
            //on that block blob upload file

            //set users profile image to the URI
            //redirect to users profile
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostProfileImg(IFormFile file)
        {
            var userId = _userManager.GetUserId(User);

            // NOTE: to use Azure web-app storage see:
            // https://docs.microsoft.com/en-us/azure/azure-app-configuration/quickstart-aspnet-core-app?tabs=core5x

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

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

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

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

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

            // On that, upload our file <-- file uploaded to the cloud
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            // Set the User's Profle Image to the URI
            await _userService.SetProfileImg(userId, blockBlob.Uri);

            // Rediredt to the User's profile page.
            return(RedirectToAction("Detail", "Profile", new { id = userId }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UploadProfileImage(IFormFile file)
        {
            var userId = _userManager.GetUserId(User);

            //Connect to Azure Storage Container
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");
            //Get Blob Container
            var container = _uploadService.GetBlobContainer(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
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            //Set the user's profile image to the received URI
            await _userService.SetProfileImage(userId, blockBlob.Uri);

            //Redirect to user's profile page

            return(RedirectToAction("Detail", "Profile", new { id = userId }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UploadProfileImage(IFormFile file)
        {
            var userName = _userManager.GetUserName(User);
            var user     = _service.GetByUserName(userName);
            var date     = user.MemberSince.Ticks;

            if (file == null)
            {
                return(RedirectToAction("Index", "Profile", new { username = userName }));
            }
            //connect to azure account container
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");
            //get the blog container
            var container = _uploadService.GetBlobContainer(connectionString, "profile-images");
            //parse the context disposition response header
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            //grab the filename
            var filename       = contentDisposition.FileName.Trim('"');
            var uniqueFileName = userName + date + filename;
            //get a refrence to a block blob
            var blockBlob = container.GetBlockBlobReference(uniqueFileName);
            //On that block blob, Upload our file <-- file uploaded to the cloud
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            //set the users profileimage to the URI
            await _service.SetProfileImage(userName, blockBlob.Uri);

            //redirects to the users's profile page
            return(RedirectToAction("Index", "Profile", new { username = userName }));
        }
Ejemplo n.º 5
0
        private CloudBlockBlob UploadForumImage(IFormFile file)
        {
            // NOTE: to use Azure web-app storage see:
            // https://docs.microsoft.com/en-us/azure/azure-app-configuration/quickstart-aspnet-core-app?tabs=core5x

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

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

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

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

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

            // On that, upload our file <-- file uploaded to the cloud/ a server
            blockBlob.UploadFromStreamAsync(file.OpenReadStream()).Wait();

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

            //Подключение к хранилищу Azure
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");

            //Получить контейнер BLOB-объектов
            var container = _uploadService.GetBlobContainer(connectionString, "profile-images");

            //Разобрать заголовок ответа Расположение содержимого
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

            //Получить имя файла
            var filename = contentDisposition.FileName.Trim('"');

            //Получить ссылку на блок Blob
            var blockBlob = container.GetBlockBlobReference(filename);

            //На этот блок BLOB Загрузить свой файл
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            //Установите изображение профиля пользователя в URI
            await _userService.SetProfileImage(userId, blockBlob.Uri);

            //Перенаправить на страницу профиля пользователя
            return(RedirectToAction("Detail", "Profile", new { id = userId }));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> UploadProfileImage(IFormFile file)
        {
            var userId = _userManager.GetUserId(User);

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

            //Get Blob container
            var container = _uploadService.GetBlobContainer(connectionString);

            // Parse Content Disposition Response Header on framework request
            //(from the file that gets passed to the method from the upload forum form)
            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 the block blob, upload our file <- file uploaded to the cloud
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

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

            //Redirect tot he Users profile page
            return(RedirectToAction("Detail", "Profile", new { id = userId }));
        }
Ejemplo n.º 8
0
        private CloudBlockBlob UploadForumImage(IFormFile file)
        {
            var connectionString   = _configuration.GetConnectionString("AzureBlobAccount");
            var container          = _uploadService.GetBlobContainer(connectionString, "forum-images");
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var fileName           = contentDisposition.FileName.Trim('"');
            var blockBlob          = container.GetBlockBlobReference(fileName);

            blockBlob.UploadFromStreamAsync(file.OpenReadStream()).Wait();
            return(blockBlob);
        }
Ejemplo n.º 9
0
        public async Task <CloudBlockBlob> GetUploadedImage(IFormFile file)
        {
            var connectionString         = _configuration["AzureStorageAccountConnectionString"];
            var container                = _uploadService.GetBlobContainer(connectionString);
            var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var filename  = Path.Combine(parsedContentDisposition.FileName.ToString().Trim('"'));
            var blockBlob = container.GetBlockBlobReference(filename);
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            return(blockBlob);
        }
Ejemplo n.º 10
0
        public CloudBlockBlob PostForumImage(IFormFile file)
        {
            var connectionString         = _configuration.GetConnectionString("DefaultConnection");
            var container                = _uploadService.GetBlobContainer(connectionString);
            var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var filename  = Path.Combine(parsedContentDisposition.FileName.ToString().Trim('"'));
            var blockBlob = container.GetBlockBlobReference(filename);

            blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            return(blockBlob);
        }
Ejemplo n.º 11
0
        public async Task<IActionResult> UploadProfileImage(IFormFile file)
        {
            var userId = _userManager.GetUserId(User);
            var connectionString = _configuration.GetConnectionString("AzureStorageAccountConnectionString");
            var container = _uploadService.GetBlobContainer(connectionString);

            var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));

            var blockBlob = container.GetBlockBlobReference(filename);

            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());
            await _userService.SetProfileImage(userId, blockBlob.Uri);

            return RedirectToAction("Detail", "Profile", new { id = userId });
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> UploadProfileImage(IFormFile file)
        {
            var userId           = _userManager.GetUserId(User);
            var connectionString = _configuration.GetConnectionString("AzureStorageAccountConnectionString");
            var container        = _uploadService.GetBlobContainer(connectionString);

            var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));

            var blockBlob = container.GetBlockBlobReference(filename);

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

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

            return(Redirect("https://traineeshipforum.azurewebsites.net/Identity/Account/Manage"));
        }
Ejemplo n.º 13
0
        public async Task UploadThreadImage(IFormFile file, int id)
        {
            var ach = _service.GetById(id);
            //connect to azure account container
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");
            //get the blog container
            var container = _uploadService.GetBlobContainer(connectionString, "achievement-images");
            //parse the context disposition response header
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            //grab the filename
            var filename = contentDisposition.FileName.Trim('"');
            //get a refrence to a block blob
            var blockBlob = container.GetBlockBlobReference(filename);
            //On that block blob, Upload our file <-- file uploaded to the cloud
            await blockBlob.UploadFromStreamAsync(file.OpenReadStream());

            //set the thread image to the URI
            await _service.UploadPicture(ach.Id, blockBlob.Uri);
        }
        public async Task <IActionResult> UploadProductImage(int id, IFormFile file)
        {
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");
            var container        = _uploadService.GetBlobContainer(connectionString, "product-images");

            var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            var filename = parsedContentDisposition.FileName.Trim('"');

            var blockBlob = container.GetBlockBlobReference(filename);

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

            var product = _ctx.Products.FirstOrDefault(x => x.Id == id);

            product.ImageURL = blockBlob.Uri.AbsoluteUri;

            await _ctx.SaveChangesAsync();

            return(RedirectToPage("/Index"));
        }
Ejemplo n.º 15
0
        private CloudBlockBlob UploadForumImage(IFormFile file)
        {
            // konek ke azure storage account container
            var connectionString = _configuration.GetConnectionString("AzureStorageAccount");

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

            // Parse the content disposition response header
            var contentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

            // ambil nama file
            var filename = contentDisposition.FileName.Trim('"');

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

            // di block blop, upload file <-- file telah diupload
            blockBlob.UploadFromStreamAsync(file.OpenReadStream()).Wait();

            return(blockBlob);
        }