To upload the image to our server, we are using postFile() on videoAPIService. Let's create this service now. Inside the client/app/services folder, create a file named video.api.service.ts and update it, as shown here:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class VideoAPIService {
constructor(private http: HttpClient) {}
postFile(threadId: string, videoBlob: File): Observable < any > {
const formData: FormData = new FormData();
formData.append('video-reply', videoBlob, videoBlob.name);
return this.http.post < any > (`/api/upload-video/${threadId}`, formData);
}
}
Finally, we need to add this service as a provider in client/app/app.module.ts. First, we will import VideoAPIService into client/app/app.module.ts:
import { VideoAPIService } from './services/video.api.service';
And update, providers as shown here:
// SNIPP SNIPP
providers: [
AuthService,
AuthGuardLogin,
AuthGuardAdmin,
UserService,
ThreadService,
MessageService,
VisionAPIService,
VideoAPIService,
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
multi: true
}
],
// SNIPP SNIPP
Save all the files and continue.