2016-11-21 8 views

答えて

2

私はそれを行う方法ですが、それは機能しています。

function _uploadFile(resourceURL, file) { 
    var deferred = $q.defer(); 
    var config = {}; 
    config.headers = {}; 
    config.transformRequest = angular.identity; 
    config.headers['Content-Type'] = undefined; 

    // config.headers['MyCustomHeaderKey'] = MyCustomHeaderValue; // Optional 

    var formData = new FormData(); 
    formData.append('file', file); 
    // formData.append('myCustomFormDataAttributeKey', myCustomFormDataAttributeValue); // Optional 

    $http.post(resourceURL, formData, config) 
     .success(function (response) { 
      deferred.resolve(response); 
     }) 
     .error(function (err, status) { 
      deferred.reject(err); 
     }); 

    return deferred.promise; 
} 

角度でのファイルアップロードについてこれは非常に良いのトピック:
How to POST JSON and a file to web service with Angular?

関連する問題