Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uploadConfigFiles(event){
- let url = "*******/uploadRawFile.do";
- console.log("File selected");
- // let inputEl = this.el.nativeElement.firstElementChild;
- let fileLocInput = event.target;
- if (fileLocInput.files.length > 0) { // a file was selected
- let file:File = fileLocInput.files[0];
- let formData:FormData = new FormData();
- formData.append("rawFile",file,file.name);
- formData.append("locationFile",file,file.name);
- let xhr: XMLHttpRequest = new XMLHttpRequest();
- xhr.onreadystatechange = () => {
- if (xhr.readyState === 4) {
- if (xhr.status === 200) {
- alert("success");
- } else {
- alert("fail");
- }
- }
- };
- xhr.open('POST', url, true);
- xhr.send(formData);
- /*
- let headers = new Headers({ 'Content-Type': 'multipart/form-data;boundary=HereGoes' }); // ... Set content type to JSON
- let options = new RequestOptions({ headers: headers }); // Create a request option
- this.http
- .post(url,formData,options)
- .map(res => res.json())
- .catch(error => Observable.throw(error))
- .subscribe(
- data => console.log('success'),
- error => console.log(error)
- )
- // do whatever you do...
- // subscribe to observable to listen for response
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement