AngularJS Uploading An Image With ng-upload

前端 未结 4 1042
清酒与你
清酒与你 2020-12-02 08:31

I am trying to upload a file in AngularJS using ng-upload but I am running into issues. My html looks like this:

4条回答
  •  孤城傲影
    2020-12-02 09:00

    In my case above mentioned methods work fine with php but when i try to upload files with these methods in node.js then i have some problem. So instead of using $http({..,..,...}) use the normal jquery ajax.

    For select file use this

    
    

    And in controller

    $scope.uploadFile = function(element) {   
    var data = new FormData();
    data.append('file', $(element)[0].files[0]);
    jQuery.ajax({
          url: 'brand/upload',
          type:'post',
          data: data,
          contentType: false,
          processData: false,
          success: function(response) {
          console.log(response);
          },
          error: function(jqXHR, textStatus, errorMessage) {
          alert('Error uploading: ' + errorMessage);
          }
     });   
    };
    

提交回复
热议问题