public async Task <bool> SetInputFile(IFormFile input)
        {
            try
            {
                _inputVideo = await input.GetBytesAsync();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error in SetInputFile()");
            }

            return(false);
        }
示例#2
0
        public async Task <ActionResult <string> > UploadUserAvatar(IFormFile file)
        {
            byte[] bytes = await file.GetBytesAsync();

            User user = await _userManager.FindByEmailFromClaimsPrincipals(HttpContext.User);

            if (await _blobService.UploadPhotoAsync(user.Email, bytes, file.ContentType))
            {
                Uri fileUri = _blobService.GetPhoto(user.Email);
                return(fileUri.AbsoluteUri + $"?t={DateTime.Now}");
            }

            return(BadRequest(new ApiResponse(400)));
        }
示例#3
0
        public async Task <UploadVCardResponseDto> UploadVCardAsync(IFormFile vCardFile)
        {
            var contentType = vCardFile.ContentType?.ToLowerInvariant();

            if (ValidVCardContentTypes.Contains(contentType) is false)
            {
                throw new InvalidOperationException($"Only accepts VCard file");
            }
            if (vCardFile.Length <= 0)
            {
                throw new InvalidOperationException("Only accepts non-Empty VCard file");
            }
            var bytes = await vCardFile.GetBytesAsync();

            return(await _mediator.Send(new UploadVCardCommand(bytes)));
        }
示例#4
0
        public async Task <IActionResult> AddImageAsync(int id, [BindRequired] IFormFile file)
        {
            if (!file.IsImage())
            {
                throw new UnsupportedContentTypeException("Uploaded file is not an image file.");
            }

            byte[] bytes = await file.GetBytesAsync();

            var image = new DTO.BreadFile()
            {
                Bytes     = bytes,
                Extension = Path.GetExtension(file.FileName)
            };

            await restaurantService.AddImageAsync(id, image);

            return(Success());
        }
        public async Task <string> PostAsync(string url, IFormFile file)
        {
            var client      = _httpClientFactory.CreateClient();
            var httpContent = new MultipartFormDataContent();

            var byteArr = await file.GetBytesAsync();

            var imageContent = new ByteArrayContent(byteArr);

            imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");

            httpContent.Add(imageContent, "image", "image.jpg");
            var response = await client.PostAsync(url, httpContent);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                return(null);
            }
            var resultStr = await response.Content.ReadAsStringAsync();

            return(resultStr);
        }
        public async Task <string> AddPhoto([FromForm] IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                throw new ArgumentNullException();
            }

            var imageName = $"{Guid.NewGuid().ToString()}.{file.ContentType.GetExtension()}";

            var fileAsBytes = await file.GetBytesAsync();

            var storageContainerName = _storageConfig.Value.PublicContainerName;

            var fileName = await _storageService.Add(fileAsBytes, storageContainerName, imageName, file.ContentType);

            var photoEntity = new Photo(fileName);
            await _context.AddAsync(photoEntity);

            await _context.SaveChangesAsync();

            var fullPath = $"{_storageConfig.Value.Url}/{storageContainerName}/{fileName}";

            return(fullPath);
        }