2017-04-05 39 views
1

我正在使用ng2-file-upload包打到ASP.NET Core後端。ng2-file-upload ASP.NET Core MVC - 大塊上傳進度

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

使用基本例如,嘗試測試大文件的上傳〜50MB。

該文件最終上傳,但沒有進展/塊動作正在發生。它基本上在坐了一會之後立即上傳。

我需要更改以獲取進度/塊上載?

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(); 
}