Angularjs $http post文件和表单数据

10 浏览
0 Comments

Angularjs $http post文件和表单数据

我在Python中有以下请求:

import requests, json, io
cookie = {}
payload = {"Name":"abc"}
url = "/test"
file = "out/test.json"
fi = {'file': ('file', open(file) )}
r = requests.post("http://192.168.1.1:8080" + url, data=payload, files=fi, cookies=cookie)
print(r.text)

它发送一个文件和表单字段给后端。我如何使用Angular $http执行相同的操作(发送文件+表单字段)?目前我这样做,但不确定如何同时发送文件。

var payload = {"Name":"abc"};
$http.post('/test', payload)
    .success(function (res) {
    //success
});

0