1.1.4 • Published 8 months ago

upload-image-gdrive v1.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

How to use:

Make sure you have a google account, and you should create a project in https://console.developers.google.com/.

Enter your project's console homepage, and go into APIs & auth -> Credentials, then add a credentials for your project.

Create credentials to GDrive API.

You can see all steps here: https://support.google.com/a/answer/7378726

Create the folder in gdrive

image image

Get the folder id

image

Share your folder

image

Add the email client as editor

image

You'll need :

  • FolderId - Id folder create in Gdrive
  • client_id: Client Id created by Gdrive API,
  • private_key: Private Key created by Gdrive API,
  • client_email: Client Email created by Gdrive API,

Add your credentials in .env, example used Nextjs :

NEXT_PUBLIC_FOLDER_ID = ""
NEXT_PUBLIC_CLIENT_ID = ""
NEXT_PUBLIC_PRIVATE_KEY = ""
NEXT_PUBLIC_CLIENT_EMAIL = "

How use ?

  npm i upload-image-gdrive
  import uploadImage from "upload-image-gdrive"
  
  const exampleFunction = async (event: Event<HTMLInputElement>) => {
    const params = {
      folderId: process.env.NEXT_PUBLIC_FOLDER_ID,
      clientId: process.env.NEXT_PUBLIC_CLIENT_ID,
      privateKey: process.env.NEXT_PUBLIC_PRIVATE_KEY,
      clientEmail: process.env.NEXT_PUBLIC_CLIENT_EMAIL,
    };
  
    const files: File[] = Array.from(event.target.files);
    const images = await Promise.all(
        files.map(
            async (file: File) =>
                await uploadImage({
                    ...params,
                    file,
                }),
        ),
    );
    return images
  }
1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago