Angular 4 Flask 1.0.2
Hi all
I am trying to upload a file from Angular by populating a new FormData() object and posting it. It appears to be posting ok, but I can't get the values from the post from within Flask.
I call this from a button click event:
UploadFile() : void{
let formModel = new FormData()
formModel.set('fileName', this.fileName);
formModel.set('fileData', this.form.get('fileData').value);
this.filesProvider.UploadFile(formModel)
.subscribe(res => {
this.UploadFileProcessed(res, true);
}
, (err) => {
this.UploadFileProcessed(err, false);
}
);
...which calls a provider...
UploadFile(formData: FormData) : Observable<Response> {
let headers = new Headers();
headers.set('Content-Type', null);
headers.set('Accept', "multipart/form-data");
headers.set('Authorization', 'Basic ' + btoa(access_token + ":"));
let requestOptions = new RequestOptions({ headers: headers })
return this.http
.post(this.globalVarsProvider.apiUrl + "member/uploadFile", formData, requestOptions)
.map((response: Response) => response);
}
On the Flask API end I have this:
@app.route('/api/member/uploadFile', methods=['POST'])
@auth.login_required
def uploadFile():
print request.form.get('key1')
return "ok"
Running this outputs "None" in the Flask dev server terminal.
If I do print request.get_data()
I see all the post data (including the crazy image data stuff).
In Chrome the request looks like this:
Any idea what I'm doing wrong please and how I get the data from within Flask?
Thanks!