Send FormData with other field in AngularJS

前端 未结 5 1106
天涯浪人
天涯浪人 2020-11-28 09:46

I have a form with two input text and one upload. I have to send it to the server but I have some problem concatenating the file with the text. The

5条回答
  •  我在风中等你
    2020-11-28 10:29

    This never gonna work, you can't stringify your FormData object.

    You should do this:

    this.uploadFileToUrl = function(file, title, text, uploadUrl){
       var fd = new FormData();
       fd.append('title', title);
       fd.append('text', text);
       fd.append('file', file);
    
         $http.post(uploadUrl, obj, {
           transformRequest: angular.identity,
           headers: {'Content-Type': undefined}
         })
      .success(function(){
        blockUI.stop();
      })
      .error(function(error){
        toaster.pop('error', 'Errore', error);
      });
    }
    

提交回复
热议问题