Veröffentlichung von Daten und Dateien mit Aurelia an ASP.NET webapi

Ich versuche, meiner Anwendung eine Eingabe mit Datei-Upload hinzuzufügen.

Dies ist meiner Ansicht nach mit zwei Eingaben, einem Text und einer Datei:

<template>
  <form class="form-horizontal" submit.delegate="doImport()">
    <div class="form-group">
      <label for="inputLangName" class="col-sm-2 control-label">Language key</label>
      <div class="col-sm-10">
        <input type="text" value.bind="languageKey" class="form-control" id="inputLangName" placeholder="Language key">
      </div>
    </div>
    <div class="form-group">
      <label for="inputFile" class="col-sm-2 control-label">Upload file</label>
      <div class="col-sm-10">
        <input type="file" class="form-control" id="inputFile" accept=".xlsx" files.bind="files">
      </div>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-default">Do import</button>
      </div>
    </div>
  </form>
</template>

In meinem Webapi habe ich diesen Code, den ich aus @ kopiert und eingefügt haHie:

public class ImportLanguageController : ApiController
{
    public async Task<HttpResponseMessage> Post()
    {
        // Check if the request contains multipart/form-data.
        if (!Request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }

        string root = HttpContext.Current.Server.MapPath("~/App_Data");
        var provider = new MultipartFormDataStreamProvider(root);

        try
        {
            // Read the form data.
            await Request.Content.ReadAsMultipartAsync(provider);

            // This illustrates how to get the file names.
            foreach (MultipartFileData file in provider.FileData)
            {
                //Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                //Trace.WriteLine("Server file path: " + file.LocalFileName);
            }
            return Request.CreateResponse(HttpStatusCode.OK);
        }
        catch (System.Exception e)
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
        }
    }
}

Nun habe ich mein Ansichtsmodell in Aurelia:

import {inject} from 'aurelia-framework';
import {HttpClient, json} from 'aurelia-fetch-client';

@inject(HttpClient)
export class Import {
  languageKey = null;
  files = null;

  constructor(http){
    http.configure(config => {
      config
        .useStandardConfiguration();
    });

    this.http = http;
  }

  doImport() {
    //What goes here??
  }
}

Also meine Frage ist, welche Logik in meiner Funktion gehtdoImport? Ich bin mir nicht sicher, ob der Code in meiner Controller-Methode in der Webapi korrekt is

Antworten auf die Frage(2)

Ihre Antwort auf die Frage