Translate

Home > April 2018

April 2018

Jquery Image to Base64 Convert ,For Servier side upload

Thursday, April 26, 2018 Category : 0


var file1;
            if (document.getElementById("inputFile").files.length > 0) {
                file1 = document.getElementById("inputFile").files[0];


                var reader = new FileReader();
                reader.readAsDataURL(file1);
                var image;
                reader.onloadend = function (e) {
                    var Image64= e.target.result;
                 // post to server
                   

                }
            }

ASP.NET Core AngularJs/Jquery File Upload

Category : 0

 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!");
              }
            }
       );

Powered by Blogger.