我正在使用ng2-file-upload
包来点击ASP.NET Core
后端。
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 controller / action:
public ActionResult Upload(IFormFile file)
{
if (file == null || file.Length == 0)
{
return NoContent();
}
// handle file here
return Ok();
}
答案 0 :(得分: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();
}