Example #1
0
        public async Task <string> UploadPhoto(IFormFile image, string currentDirectory)
        {
            if (image == null || image.Length == 0)
            {
                throw new NullReferenceException("no file chosen.");
            }

            var folderPath = _fileHandler.GetAbsolutePath(currentDirectory);

            _fileHandler.CreateDirectory(folderPath);

            var randomFileName = _fileHandler.GetRandomFileName(image.FileName);

            var photoPath = _fileHandler.Combine(folderPath, randomFileName);

            using (var stream = new FileStream(photoPath, FileMode.Create))
            {
                await image.CopyToAsync(stream);
            }

            return(randomFileName);
        }