I have an interface in Angular2 and a back end in Java. I work with Java and found this task with Angular a bit complicated.
I need to upload a file in a form. How to add a file to a form object, as well as other field values. Is it even possible?
I mean this one
onSubmit() { if (this.isSubmitting) return; this.isSubmitting = true; let newService = { name: this.editServiceForm.value.name, summary: this.editServiceForm.value.summary logo: this.editServiceForm.value.logo <-----------like this };
when I do this, I get an empty string for the logo. all other "normal" line strings are correct.
I saw many file upload solutions here in StackOverflow, all of which describe file uploads in a separate request. like this template: <div> <input type="file" (change)="onChange($event)"/> </div> ,
.....
onChange(event) { console.log('onChange'); var files = event.srcElement.files; console.log(files); this.service.makeFileRequest('http://localhost:8182/upload', [], files).subscribe(() => { console.log('sent'); }); }
here in this.service.makeFileRequest, we send a request specifically for downloading the file.
If I do this, I need to process this request separately, and then other data from the form separately (for example, name and resume). If so, what would be the proper way to handle this in java?
rigby source share