2

我正在使用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 控制器/动作:

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

        // handle file here

        return Ok();
    }
4

1 回答 1

1

当您要求将 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();
}
于 2017-11-14T05:12:24.780 回答