Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

Correct javascript call to upload file via web api

$
0
0

I have a javascript function as so:

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();
        }
    });
}

Im trying to find the correct call to import the file so it matches the C# API object as so:

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

The call goes through but the physical file is empty. What am I missing?


Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>