Send Excel File to ASP.NET Web API

2020-08-01 02:36发布

问题:

How do I send an excel file coming from file upload input to my ASP.NET WebAPI and then save that excel file so I can read its data?

Here's what I've got (button click calls upload()) - just the basics, which works fine:

    function upload() {
        $.getJSON("api/uploads/uploadfile",
            function (data) {
                $("#mydiv").append("Success: " + data.Success + " Failed: " + data.Failed);
            });
    }

And my ASP.NET WebAPI method:

    public DBResult UploadFile()
    {
        DBResult result = new DBResult();
        result.Success = 0;
        result.Failed = 0; 

        return result;
    }

Any help is greatly appreciated.

TIA

回答1:

I was able to figure this out between these 2 articles:

How To Accept a File POST

http://www.strathweb.com/2012/04/html5-drag-and-drop-asynchronous-multi-file-upload-with-asp-net-webapi/



回答2:

I posted a similar solution at another question, but using c# to post to webapi:
How To Accept a File POST