2.1.1 • Published 2 years ago

ng-fad-google-drive v2.1.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Getting started

Installation

npm install ng-fad-google-drive

It is important to configure your application in: Click here

Description

a) Gets the list of files on google drive. The search is done by filtering through a query b) Gets the base64 and blob of the selected file

Dependencies

npm install @fadportal/portal-models

Import

In the file necessary example.component.ts import the service.

import { FadGoogleDriveService } from 'ng-fad-google-drive';
.
.
.
...  constructor(private googleDrive: FadGoogleDriveService) { }

Usage

Typescript

Inject service called FadGoogleDriveService Before using any method it is important to initialize that google drive requires with the method initGoogleDrive To see the errors it is necessary to subscribe to the method onErrorGoogleDrive

  private API_KEY = 'YOUR_GOOGLE_API_KEY';
  private CLIENT_ID = 'YOUR_GOOGLE_CLIENT_ID';

  constructor(private googleDrive: FadGoogleDriveService) { }

  ngOnInit(): void {
    // Observe errors
    this.onerror();

    // Observe files
    this.ongetfiles();
  }

  async getFiles() {
    /**
     * Initializaton of Google Drive
     * @param {string} apiKey Necessary data to initialize google
     * @param {string} clientId Necessary data to initialize google
     * @return {Promise<boolean>}
     */
    const init = await this.oneDrive.initGoogleDrive(this.API_KEY, this.CLIENT_ID);

    if (init) {
      /**
       * Trigger Google Drive files
       * @param {string} q Filter to Google Drive list (view Google documentation)
       * @param {number} pageSize Number of files per response. By default it is 100
       */
      const q = "mimeType='application/pdf'"
      const pageSize = 10;
      this.googleDrive.getGoogleDriveFiles(q, pageSize);
    }
  }

  async getFile(fileId: string, mimeType: string) {
    /**
     * Get base64 of Google Drive file
     * @param {string} mimeType Format of your file (is provided for each item in the Google Drive document list)
     * @return {Promise<FadGoogleDriveModelFileFormat>}
     */

    const data = await this.googleDrive.getGoogleDriveFile(fileId, mimeType);
    console.log(data);
  }

  ongetfiles() {
    /**
     * Get items from a google drive account 
     * @return {Observable<FadGoogleDriveModelFileList[]>}
     */

    this.googleDrive.onGetGoogleDriveFiles().subscribe(res => {
      // Google Drive files
      console.log(res);
    });
  }

  onerror() {
    /**
     * Get errors from service
     * @return {Observable<FadPortalModelErrorModule>}
     */

    this.googleDrive.onErrorGoogleDriveFiles().subscribe(res => {
      // Manage errors
      console.log(res);
    });
  }