Translate

> > ASP.NET Core AngularJs/Jquery File Upload

ASP.NET Core AngularJs/Jquery File Upload

Posted on Thursday, April 26, 2018 | No Comments

 public class FileInputModel
    {
        public IFormFile FileToUpload { get; set; }
        public string UserId { get; set; }
    }


API Class

 public class FileUploadController : Controller
    {
        [HttpPost]
        [Route("api/fileupload/CustomerExcelUpload2")]
   
        public IActionResult CustomerExcelUpload2(FileInputModel file)
        {

        }



}


For AngularJs :


return $http({
            url: serviceBasePath + '/api/fileupload',
            method: 'POST',
            //data: JSON.stringify(data),
            processData: false,
            contentType: false,
            data: (data),
            headers: { 'content-type': undefined }
            , transformRequest: angular.identity
        }).success(function (d) {
            defer.resolve(d);
        }).error(function (error) {
            defer.reject();
            ShowMsg(error.ExceptionMessage);
        })
            ;



Jquery



 $.ajax(
            {
                url:  'http://localhost:8094/api/fileupload/CustomerExcelUpload',
               data: formData,
                processData: false,
                contentType: false,
                type: "POST",
                success: function (data) {
                    alert("Files Uploaded!");
              }
            }
       );

Leave a Reply

Powered by Blogger.