1.0.8 • Published 2 years ago

google-drive-crud v1.0.8

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

Installation

# using npm
npm install google-drive-crud

Usage

# using require
// 1. initialzie google drive with credentials.json file

const gDrive = require('google-drive-crud');

const gDriveInstance = new gDrive('./credentials.json');

gDriveInstance.initializeDrive();

const ROOT_FOLDER = null

async function test() {
    try {
        1. Upload File Demo
         if rootFolder id is available then pass array of id's ['id1', 'id2]
         else pass rootFolder as null value
         Function Arguments - 
         1.FileName - File name with file extension (File will be uploaded with this name to drive)
         2.MimeType - File MimeType as shown in below example
         3.FilePath - Absolute or relative path of file on the local drive including file name to upload
         4.RootFolder - The file will be stored inside this folder id.
         If you want to store file inside root folder then pass this value as null
         If you want to store file into sub folders then you can pass an array of folder id's

        let fileUploadResp = await gDriveInstance.fileUpload('test.pdf', 'application/pdf', './test.pdf', ['folderid1', 'folderid2'])
        console.log(fileUploadResp)

        2. Get Files List from Drive
         Function Arguments - 
         1.Parent Id - Id of parent folder inside which this file is stored.
         If file is stored in root folder, then pass this paramter as null

        let filesList = await gDriveInstance.listFiles(null)
        console.log(filesList)

        3. Download File from Drive
         Function Arguments - 
         1.FileId - Id of file from google drive
         2.FileName - File name with file extension (After download file will be stored with this name on local drive)
         3.DownloadPath - Absolute or relative path of folder inside which file should be downloaded

        let fileDownloadResp = await gDriveInstance.fileDownload('1VtJRScm_xfApND-19ziO2k26_S3PZs1-', 'test.pdf', 'download')
        console.log(fileDownloadResp)
        
    } catch (error) {
        console.log(error)
    }
}
test()