Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. uploadConfigFiles(event){
  2. let url = "*******/uploadRawFile.do";
  3. console.log("File selected");
  4. // let inputEl = this.el.nativeElement.firstElementChild;
  5. let fileLocInput = event.target;
  6. if (fileLocInput.files.length > 0) { // a file was selected
  7. let file:File = fileLocInput.files[0];
  8.  
  9. let formData:FormData = new FormData();
  10. formData.append("rawFile",file,file.name);
  11. formData.append("locationFile",file,file.name);
  12. let xhr: XMLHttpRequest = new XMLHttpRequest();
  13.  
  14.  
  15. xhr.onreadystatechange = () => {
  16. if (xhr.readyState === 4) {
  17. if (xhr.status === 200) {
  18. alert("success");
  19. } else {
  20. alert("fail");
  21. }
  22. }
  23. };
  24.  
  25.  
  26. xhr.open('POST', url, true);
  27. xhr.send(formData);
  28. /*
  29. let headers = new Headers({ 'Content-Type': 'multipart/form-data;boundary=HereGoes' }); // ... Set content type to JSON
  30. let options = new RequestOptions({ headers: headers }); // Create a request option
  31. this.http
  32. .post(url,formData,options)
  33. .map(res => res.json())
  34. .catch(error => Observable.throw(error))
  35. .subscribe(
  36. data => console.log('success'),
  37. error => console.log(error)
  38. )
  39. // do whatever you do...
  40. // subscribe to observable to listen for response
  41.  
  42. */
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement