import { Injectable, OnInit, AfterViewInit} from '@angular/core'; import { Jsonp, URLSearchParams, Http, RequestOptions, Headers as MyHeader } from '@angular/http'; import { HttpClient, HttpErrorResponse , HttpHeaders } from '@angular/common/http'; import { Observable} from 'rxjs/Observable'; import { promise } from 'selenium-webdriver'; import { RequestOptionsArgs } from '@angular/http/src/interfaces'; @Injectable() export class DataService implements OnInit { private headers = new Headers({'Content-Type': 'application/json'}); private defaultUrl :string; // URL to external web a private urlDictionary = { Mailbox:'/api/mailboxes', Reason:'/api/reasons', MailboxNamePrompt: '/api/mailboxes/nameprompt' }; restApiName = "ccadmin"; ngOnInit(): void { } // Class constructor with Jsonp injected constructor(private jsonp: Jsonp, private http:HttpClient) { this.defaultUrl = "http://nz-aleyoon.edge.local:5013/api/mailboxes/nameprompt/18"; } public downloadStream(id: number): Observable { var Url = "http://nz-aleyoon.edge.local:5013/api/mailboxes/"+id+ "/nameprompt"; return this.http.get(Url, {responseType: "blob"} ) } public uploadStream(id: number, blob: Blob):Observable { const headers = new HttpHeaders(); headers.append('Content-Type', 'multipart/form-data'); //var args:RequestOptionsArgs = {headers:aaa}; //var options = {headers:aaa}; var fd = new FormData(); fd.append('id', id.toString()); //fd.append('id2', id.toString()); // var fileOfBlob = new FileReader(); // fileOfBlob.readAsArrayBuffer(blob); var fileOfBlob = new File([blob], 'test.wav'); fd.append('file', fileOfBlob, "test.wav"); var url = "http://nz-aleyoon.edge.local:5013/api/mailboxes/"+id +"/nameprompt"; console.log("pre upload blob started.." + url) return this.http.post(url, fd, {headers: headers}); } }