private async Task <string> _commitImage(string id, IFormFile image, string subDirectory)
        {
            if (image is null)
            {
                throw new InvalidOperationException("Image in stream is null");
            }

            if (image is null || image.Length == 0)
            {
                throw new InvalidOperationException("Image in stream has zero length");
            }

            if (image.Length > _imageFileStorageSettings.MaxUploadFileSize)
            {
                throw new InvalidOperationException("Maximum file size exceeded");
            }

            if (!_imageFileStorageSettings.IsSupported(image.FileName))
            {
                throw new InvalidOperationException("Invalid file type");
            }

            var cacheFile = await CachedFormFileStorage.CacheItem(System.IO.Path.GetTempPath(), image);

            var(finishedFile, extension) = await ImageUtils.ConvertFile(cacheFile, id);

            var destinationFile = $"{subDirectory}/{id}.{extension}";

            await _fileUploader.UploadFile(
                finishedFile,
                _imageFileStorageSettings.ContainerName,
                destinationFile,
                "image/png",
                (p, t) => _logger.LogDebug($"Uploading image: {p} - {t}")
                );

            return(destinationFile);
        }
        public async Task <IActionResult> Upload(string slug, IFormFile file)
        {
            _logger.LogDebug($"Uploading file for: {slug}");
            if (file is null || file.Length == 0)
            {
                return(BadRequest("No file found in stream"));
            }
            if (file.Length > _audioFileStorageSettings.MaxUploadFileSize)
            {
                return(BadRequest("Maximum file size exceeded"));
            }
            if (!_audioFileStorageSettings.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid file type"));
            }

            var podcast = await _podcastRepository.GetForUserAndSlugAsync(_applicationUser.Slug, slug);

            if (podcast is null)
            {
                _logger.LogError($"Unable to find podcast");
                return(NotFound());
            }

            var entry = new PodcastEntry {
                Title            = Path.GetFileName(Path.GetFileNameWithoutExtension(file.FileName)),
                ImageUrl         = $"{_storageSettings.CdnUrl}/static/images/default-entry.png",
                Processed        = false,
                ProcessingStatus = ProcessingStatus.Processing,
                Podcast          = podcast
            };

            var localFile = await CachedFormFileStorage.CacheItem(_hostingEnvironment.WebRootPath, file);

            _logger.LogDebug($"Local file is: {localFile}");

            _entryRepository.AddOrUpdate(entry);

            _logger.LogDebug("Completing uow");
            await _unitOfWork.CompleteAsync();

            var authToken = _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"].ToString();

            if (string.IsNullOrEmpty(authToken))
            {
                return(Unauthorized("Auth token is empty"));
            }

            //convert uploaded file to extension
            var audioUrl = localFile
                           .Replace(_hostingEnvironment.WebRootPath, string.Empty)
                           .Replace(@"\", "/");

            _logger.LogDebug($"Starting processing jobs for url: {audioUrl}");

            BackgroundJob.Enqueue <ProcessNewEntryJob>(e =>
                                                       e.ProcessEntryFromUploadFile(entry.Id, audioUrl, authToken, null));

            var ret = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry);

            return(Ok(ret));
        }