Multipart request with AngularJS

后端 未结 5 1384
说谎
说谎 2020-12-30 02:20

I have an API endpoint to which I must send a multipart HTTP request, composed of two parts, file (a file system file) and data (a JSON object).

5条回答
  •  执笔经年
    2020-12-30 02:39

    what i did to solve this was.

    var formData = new FormData(document.getElementById('myFormId'));
    

    then in my service

                    var deferred = $q.defer();
                    $http.post('myurl', formData, {
                        cache: false,
                        contentType: false,
                        processData: false,
                    })
                        .success(function (response) {
                            deferred.resolve(response);
                        })
                        .error(function (reject) {
                            deferred.reject(reject);
                        });
                    return deferred.promise;
    

提交回复
热议问题