.net core webApi 上传附件

1、前端

 <form method="post" enctype="multipart/form-data" id="form">
       名称:<input type="file" name="name"  id="name"/>
        文件:<input type="file" name="UploadFile"  id="files"/>
        <input type="button" id="saves" value="提交" />
</form>
    $("#saves").on("click", function (e) {
        var form =document.getElementById("form");
        var data = new FormData(form);
        $.ajax({
            url: "http://localhost:10062/api/Files/Add",
            type: "post",
            dataType: "json",
            contentType: false,
            processData: false,
            headers: { 'X-Custom-Source': 'browser', "Authorization":"Bearer token"},
            data: data,
            success: function (res) {
                if (res.status == 200) {
                }

            }
        });
    });

2、后端

  

public void Add([FromForm]Files file)//Files是自己定义的类
{

}
原文地址:https://www.cnblogs.com/study10000/p/10643564.html