Creating the audio API service

To upload the audio to our server, we are using postFile() on audioAPIService. Let's create this service now. Inside the client/app/services folder, create a file name audio.api.service.ts and update it, as shown here:

// SNIPP SNIPP
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class AudioAPIService {
constructor(private http: HttpClient) {}
postFile(threadId: string, audioBlob: File): Observable < any > {
const formData: FormData = new FormData();
formData.append('audio-reply', audioBlob, audioBlob.name);
return this.http.post < any > (`/api/upload-audio/${threadId}`, formData);
}
}
// SNIPP SNIPP

We need to add this service as a provider in client/app/app.module.ts. First, we will import AudioAPIServiceinto client/app/app.module.ts:

// SNIPP SNIPP
import { AudioAPIService } from './services/audio.api.service';
// SNIPP SNIPP

Update the providers, as shown here:

// SNIPP SNIPP
providers: [
AuthService,
AuthGuardLogin,
AuthGuardAdmin,
UserService,
ThreadService,
MessageService,
VisionAPIService,
VideoAPIService,
AudioAPIService,
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
multi: true
}
],
// SNIPP SNIPP

Save all the files to continue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.52.188