【问题标题】:ng2-file-upload ASP.NET Core MVC - Chunk Upload Progressng2-file-upload ASP.NET Core MVC - 块上传进度
【发布时间】:2017-04-05 22:53:35
【问题描述】:

我正在使用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();
    }

【问题讨论】:

  • 嗨,你有什么解决办法吗?

标签: file-upload asp.net-core-mvc ng2-file-upload


【解决方案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();
}

【讨论】:

    猜你喜欢
    • 2020-01-15
    • 1970-01-01
    • 2018-05-20
    • 2019-06-30
    • 2017-07-19
    • 2020-01-07
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    相关资源
    最近更新 更多