Exemplo n.º 1
0
        public async Task <ActionResult> UploadChunk([FromForm] FileChunkViewModel fileChunkViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            var    file          = fileChunkViewModel.file;//文件
            string temporaryFile = Path.Combine($"{Directory.GetCurrentDirectory()}/wwwroot/", "Chunk" + fileChunkViewModel.Filename);

            if (!Directory.Exists(temporaryFile))
            {
                Directory.CreateDirectory(temporaryFile);
            }
            string tempPath = Path.Combine(temporaryFile, fileChunkViewModel.ChunkNumber.ToString());

            if (!Convert.IsDBNull(file))
            {
                await FileHelper.CreateFileAsync(file, tempPath);
            }

            var fileInfo = _mapper.Map <FileChunk>(fileChunkViewModel);
            int result   = await _fileChunkRepository.AddAsync(fileInfo);

            return(Ok());
        }