Code Monkey home page Code Monkey logo

google-drive-manage's Introduction

Google Drive folder management

It is the project which is based on node.js with googleapis package to handle google drive folder and it's inner files or folders. This is only backend with four APIs to list, upload file/files, download with public url and the last one is to delete the file.

To get credentials of google console to interact with google drive, please follow below steps -

1. Go to google console.

2. On Welcome page go to API and Services and search under library "google drive api".

3. Select first item and enable the api then click on Manage button

4. In credentials section, click on create credentials and choose service account then fill the form and download the credentials in json file.

5. Copy the email and go to your desired google drive and share any folder to that email.

Now, you can continue with project, follow these steps after clone or fork the repository -

Environment variables

Create a .env file to manage these variables :

    DRIVE_FOLDER_ID = (required) the folder id, in which you want to do management
    CLIENT_EMAIL = (required)  client_email, which you got from service account of google drive json file
    PRIVATE_KEY = (required)  private_key, which you got from service account of google drive json file

Commands to start the project

    npm install
    npm run dev

The project will run on - http://localhost:5000

How to interact with provided google drive folder

We have four APIs to perform actions like list, upload and download a file or files :

1. To upload a file

Please copy this curl to upload any file or files -

curl --location 'http://localhost:5000/api/v1/uploadFiles' \
--form 'files=@"/D:/pictures/Screenshots/corner.png"'

Note: Provide file/files from your local machine to upload.

The reponse of above API, if Successfully uploaded, will look like below -

{
    "status": "success",
    "message": "Successfully uploaded files/file."
}

2. To list the files

Please copy this curl to get the list of files -

curl --location 'http://localhost:5000/api/v1/listFiles?limit=number&nextPageToken=--next-page-token---'

The reponse of above API, if Successfully uploaded, will look like below -

{
    "status": "success",
    "nextPageToken": "nextPageTokenString",
    "files": [
        {
            "id": "1nextOvZoFWM3U5EUGG17QkdqBeB-5wgp",
            "name": "Screenshot 2023-09-21 145628.png"
        },
        {
            "id": "12lGSX78F3LU4Uz6dAX1INea2fNau2GSj",
            "name": "Screenshot 2023-09-21 145616.png"
        },
        {
            "id": "1PQSUrmZiMzZtSCsECLe-5f1eSdoSPvmg",
            "name": "Screenshot 2023-09-20 192557.png"
        },
        {
            "id": "1WYOBEW98R6WpfEsyKAcGyz2FFWMW8y-x",
            "name": "Screenshot 2023-09-13 194705.png"
        },
        {
            "id": "1quwpIqwpAFprn_gZLxf1IwWGMPeEw2VG",
            "name": "Screenshot 2023-09-13 185404.png"
        }
    ]
}

3. To delete the file using file id

Please copy this curl to delete the file using file id -

curl --location 'http://localhost:5000/api/v1/deleteFile/:id'

Note: Don't forget to replace ':id' with a file id.

The reponse of above API, if Successfully uploaded, will look like below -

{
    "status": "success",
    "message": "Successfully, deleted file"
}

4. To get the public url with download link

Please copy this curl to get the public url with download link if file exists -

curl --location 'http://localhost:5000/api/v1/publicUrl/:id'

Note: Don't forget to replace ':id' with a file id.

The reponse of above API, if Successfully uploaded, will look like below -

{
    "status": "success",
    "webContentLink": "Google_drive_download_link",
    "webViewLink": "Public_url_to_view_file"
}

Important Links for documentation

Author

Sumit Baghel

google-drive-manage's People

Contributors

baghel-sumit avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.