Send multipart/form-data files with angular using $http

后端 未结 3 1075
予麋鹿
予麋鹿 2020-11-30 01:17

I know there are a lot of questions about this, but I can\'t get this to work:

I want to upload a file from input to a server in multipart/form-data

I\'ve tr

3条回答
  •  无人及你
    2020-11-30 01:43

    Take a look at the FormData object: https://developer.mozilla.org/en/docs/Web/API/FormData

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

提交回复
热议问题