Creating  the Vision API service

To upload the image to our server, we are using postFile() on VisionAPIService. Let's create this service now. Inside the client\app\services folder, create a file named vision.api.service.ts and update it as follows:

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

Get Google Cloud AI Services Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.