2017-04-05 10 views
1

ASP.NET Coreバックエンドになるng2-file-uploadパッケージを使用しています。大きなファイルのアップロード〜50メガバイトをテストしようとすると、ベースの例を使用してng2-file-upload ASP.NET Core 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コントローラ/アクション:

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

     // handle file here 

     return Ok(); 
    } 

答えて

0

IFormFileをパラメータとしてアクションに渡されるためにあなたが尋ねるとき、それは意志アクションを処理するには、ファイル全体をロードする必要があります。代わりに、現在のリクエストから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(); 
}