Have a Query guys, please help me executing it!! I am not getting the desire result, The upload file function is not working as per requirement.The error block is executing instead of the actual function block.
main.component.ts:
uploadFile() {
console.log('Inside uploadFile');
const files: FileList = this.fileInput.nativeElement.files;
console.log('Inside uploadFile line 02');
if (files.length === 0) {
console.log('Inside uploadFile 03');
console.log('no file content here');
console.log('Inside uploadFile 04');
return;
};
console.log('Inside uploadFile 05');
this.restservice.parseTable(files).subscribe((data: any) => {
console.log('Inside uploadFile 06');
console.log('Data that i am sending: ' + data);
}, (error) => {
console.log('Inside uploadFile 07');
console.log('No Data Found' + error);
});
}
Service.ts:
parseTable(files) {
console.log('Inside parsetable function 01');
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'multipart/form-data',
})
};
console.log('Inside parsetable function 02');
const formData: FormData = new FormData();
formData.append('file', files[0], files[0].name);
console.log('Inside parsetable function 03');
return this.http.post(this.backendAddress, formData, httpOptions);
}
App.py:
@app.route('/uploader', methods = ['POST','GET'])
#@cross_origin(["http://localhost:4200"])
@cross_origin(allow_headers=['http://localhost:4200'])
def upload_file():
print(request.files)
# check if the post request has the file part
if 'file' not in request.files:
print('no file in request')
return"no file in request"
file = request.files['file']
if file.filename == '':
print('no selected file')
return"no selected file"
if file and allowed_file(file.filename):
print("hello")
filename = secure_filename(file.filename)
#file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return "Successful"
print("end")
return"Bye"
OUTPUT:
Inside handleFileInput
Inside uploadFile
Inside uploadFile line 02
Inside uploadFile 05
Inside parsetable function 01
Inside parsetable function 02
Inside parsetable function 03
Inside uploadFile 07
No Data Found[object Object]
Aucun commentaire:
Enregistrer un commentaire