2017-04-05 1 views
1

ASP.NET Core 백엔드에 ng2-file-upload 패키지가 사용 중입니다. 큰 파일 업로드 ~ 50 메가 바이트 테스트하기 위해 노력하고, 기본 예제를 사용ng2-file-upload ASP.NET 코어 MVC - 청크 업로드 진행

https://github.com/valor-software/ng2-file-upload

.

파일이 결국 업로드되지만 진행/청크 동작이 일어나지 않습니다. 잠시 앉아서 한 번에 모든 것을 업로드합니다.

진행률/청크 업로드를 변경하려면 무엇을 변경해야합니까?

NG2 구성 요소 :

import { Component, OnInit } from '@angular/core'; 
import { FileUploader } from 'ng2-file-upload'; 

@Component({ 
    selector: 'fileupload', 
    templateUrl: './fileupload.component.html' 
}) 
export class FileUploadComponent implements OnInit { 

    public uploader: FileUploader = new FileUploader({ url: '/api/purchaseorder/upload' }); 

    ngOnInit() { 

     this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => { 

      console.log("ImageUpload:uploaded:", item, status); 
     }; 
    } 

    public hasBaseDropZoneOver: boolean = false; 
    public hasAnotherDropZoneOver: boolean = false; 

    public fileOverBase(e: any): void { 
     this.hasBaseDropZoneOver = e; 
    } 

    public fileOverAnother(e: any): void { 
     this.hasAnotherDropZoneOver = e; 
    } 
} 

asp.net MVC 컨트롤러/액션이 : 당신이 IFormFile을 요청하는 경우

public ActionResult Upload(IFormFile file) 
    { 
     if (file == null || file.Length == 0) 
     { 
      return NoContent(); 
     } 

     // handle file here 

     return Ok(); 
    } 

답변

0

매개 변수로 행동으로 전달하기 위해서는 것 작업을 처리하기 전에 전체 파일을로드해야합니다. 대신 IFormFile을 현재 요청에서 다음과 같이 당깁니다.

public ActionResult Upload() 
{ 
    foreach (IFormFile file in Request.Form.Files) 
    { 
     if (file == null || file.Length == 0) 
     { 
      return NoContent(); 
     } 

     // handle file here 
     var stream = file.OpenReadStream(); 
    { 

    return Ok(); 
}