public void ThenIShouldBeAbleToGetFileInfo(FileResponseDto fileInfo) { var apiResponse = ContextHelper.GetFromContext <ApiResponse>("LastApiResponse"); var actualFileInfo = apiResponse.Content <FileResponseDto>(); actualFileInfo.ShouldBeEquivalentTo(fileInfo, options => options.Including(f => f.Name)); }
public async Task <ApiResponse <FileResponseDto> > Upload_Big_File([FromServices] IWebHostEnvironment environment) { //List<string> allowPicSuffixAr = new List<string> { ".jpg", ".png", ".jpeg", ".gif",".bmp" }; //List<string> allowViewSuffixAr = new List<string> { ".mp4", ".mkv", ".mov", ".m4v",".wmv",".avi" , ".flv" }; ApiResponse <FileResponseDto> response = new ApiResponse <FileResponseDto>(); if (Request.ContentLength == 0) { throw new ServiceException(ErrorDescriptor.FILE_NULL); } var file = Request.Form.Files["file"]; string suffix = Request.Form["suffix"]; //int flag = -1; //if (allowPicSuffixAr.Contains(suffix)) //{ // flag = 0; //} //if (allowViewSuffixAr.Contains(suffix)) //{ // flag = 1; //} //if (flag==-1) //{ // throw new ServiceException(ErrorDescriptor.FILE_FORMAT_ERROR); //} string envPath = Path.Combine(environment.WebRootPath, Appsettings.app(new string[] { "UploadFilePath", "TempPath" })); var fileName = Request.Form["name"]; var index = Request.Form["chunk"].ToString().ObjToInt(); var maxChunk = Request.Form["maxChunk"].ToString().ObjToInt(); var guid = Request.Form["guid"]; var dir = Path.Combine(envPath, guid); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var filePath = Path.Combine(dir, index.ToString()); var filePathWithFileName = string.Concat(filePath, fileName); using (var stream = new FileStream(filePathWithFileName, FileMode.Create)) { await file.CopyToAsync(stream); } var fileResponseDto = new FileResponseDto(); if (index == maxChunk - 1) { await MergeFileAsync(environment.WebRootPath, fileName, dir); fileResponseDto.Completed = true; } response.Data = fileResponseDto; return(response); }