upload-image-gdrive
v1.1.4
Published
Service to upload images in GDrive folders
Downloads
44
Maintainers
Readme
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
Get the folder id
Share your folder
Add the email client as editor
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
}