0

我有一个javascript函数:

function uploadFiles(PIRid) {
var fileInput = $('#incidentFiles');

var fileCount = fileInput[0].files.length;
for (i = 0; i < fileCount; i++){
    var Obj = new Object();
    Obj.Name = fileInput[0].files[i].name;
    var reader = new FileReader();
    Obj.File = reader.readAsBinaryString(fileInput[0].files[i]);
    Obj.PIRid = PIRid;
    Obj.RemoteID = RemoteID;
    var data = JSON.stringify(Obj);
    $.ajax({
        type: "POST",
        url: BaseHref + "/api/PIRfiles/",
        data: data,
        contentType: "application/json; charset=UTF-8",
        success: function (response) {
            $('#SaveSuccess').modal();
        },
        error: function (e) {
            $('#SaveFailure').modal();
        }
    });
}

我试图找到正确的调用来导入文件,以便它与 C# API 对象匹配,如下所示:

public class ApiPIRfile
{
    public string Name;
    public byte[] File;
    public string PIRid;
    public string RemoteID;
}

呼叫通过,但物理文件为空。我错过了什么?

4

0 回答 0