HttpContext.Current.Request.Files, не содержащие ничего при публикации данных форм через угловой - PullRequest
0 голосов
/ 09 июля 2019

Я пытаюсь загрузить файл в угловом формате, инкапсулируя файл в formdata и вызывая веб-метод asp.net.HttpContext.Current.Request.Files.Count всегда возвращает 0. Любая причина, по которой данные форм не публикуются.Я делаю что-то не так?Я вижу, как формальные данные правильно встраиваются в угловые перед вызовом метода

Компонент

import { NgxFileDropEntry, FileSystemFileEntry, FileSystemDirectoryEntry } from 'ngx-file-drop';

export interface IDocumentUpload {
    fileDropEntry: NgxFileDropEntry;
    name: string;
    selectedDocumentItem: { 'Id': number; 'Name': string; }
    selectedDate: Date;

}
    public files: IDocumentUpload[] = [];


    public uploadDocument(ids: number[]) {
        const formData = new FormData();

        let inx = 1;

        this.files.forEach(x => {
            const fileEntry = x.fileDropEntry.fileEntry as FileSystemFileEntry;
            fileEntry.file((file: File) => {
            formData.append('file' + inx++, file, x.name);
            });

            this.documentUploadService.UploadDocument(formData).then(data => {

                this.getDocumentUploadDetailsByIds(this.documentIds.ids.toString());
                this.setGridOptions();
                this.setColumns();
                this.notify.success('Documents uploaded Successfully');
                this.upload = true;
            })
        });


    }



       UploadDocument(formData: any) {
                return this.mgr360CommonService.httpPostAsync('/api/documentupload/uploadDocument',formData); 
        }


    httpPostAsync(url: string, model: any) {
        return this.httpClient.post(this.webApiLocation + url, model, httpPostOptions)
            .pipe(map((response: Response) => {
                return response;
            }))
            .toPromise()
            .catch((error: any) => {
                this.onError(error);
                return Promise.reject(error);
            });
    }

asp.net webap

[HttpPost]
    [SkipTokenAuthorization]
    [Route("api/documentupload/uploadDocument")]
    public IHttpActionResult uploadDocument()
    {
        HttpResponseMessage response;
        var mgrDocumentService = GetService<DOCUMENT>();


        if (HttpContext.Current.Request.Files.Count == 0)
            return null;

        var attachmentIds = new List<int>();
        foreach (string fileName in HttpContext.Current.Request.Files)
        {
            var file = HttpContext.Current.Request.Files[fileName];
            if (file != null && file.ContentLength > 0)
            {
                Stream fs = file.InputStream;
                BinaryReader br = new BinaryReader(fs);
                byte[] bytes = br.ReadBytes((Int32)fs.Length);

            }
            else
            {
                throw new Exception("The file is missing.");
            }

        //return  response = Request.CreateResponse(HttpStatusCode.OK, mgrStrategyDocument);
    }
        return null;

    }

Снимок экрана console.log (formData)

enter image description here

...