我想从angularjs2应用程序上传文件到python服务器应用程序。
表单数据在发送到服务器之前看起来很完美。包含名称和文件数据。
另一端是等待接受文件数据的pythonapi。但我没有得到数据。调试器PDB被激活,因为发送是由angularjs2应用程序完成的,但我缺少文件数据。
我会做错什么?
在上传.service.ts
import {Injectable} from 'angular2/core';
import {Http, Headers} from 'angular2/http';
@Injectable()
export class UploadService {
constructor(private http: Http) { }
uploader(files: any) {
let xhr = new XMLHttpRequest();
const formData = new FormData();
for(var i = 0; i < files.length; i++){
formData.append(files[i].name, files[i]);
}
var headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(JSON.parse(xhr.response))
} else {
reject(xhr.response)
}
}
}
xhr.open('POST','http://192.168.1.205:5000/zino', true)
xhr.send(formData)
}
}
python烧瓶API调试器
如你所见请求值为空:(
^{pr2}$
这是RC angular2的一个工作示例
在python端,您可以在
^{pr2}$相关问题 更多 >
编程相关推荐