Do angular2 supports multipart form submit, any example available?
Any link to docs specific to this is much appreciated
See post from angular github https://github.com/angular/angular/issues/6030
**** Updated later with Working Demo using XMLHttpRequest ****
Any example showcasing sending FormData as part of http,
Below is a draft code which works fine for me but like to know if same supported in http
HTML
<input id="single_f_fileup" [(ngModel)]="model.image" type="file" (change)="selectFile($event)" name="single_fileup" />
ANGULAR2
selectFile($event): void {
var files = $event.target.files || $event.srcElement.files;
var file = files[0];
let formData = new FormData();
formData.append("single_fileup", file);
formData.append('key1', 'value1');
formData.append('key2', 'value2');
var req = new XMLHttpRequest();
req.open("POST", "/api/fileupload");
req.send(formData);
}
NODEJS 6.2
var multer = require('multer');
var storage = multer.memoryStorage();
var upload = multer({ storage: storage });
router.post('/api/fileupload', upload.single('single_fileup'), function(req, res, next){
console.log(req.body,req.file);
});
How to make below code work?
this.http.post('/api/fileupload', formData)
.map(this.extractData)
.catch(this.handleError);