npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multer-google-drive-teams-storage

v1.1.0

Published

Multer Storage for upload files to Google Drive Teams

Downloads

4

Readme

Google Drive Teams Storage

A simple storage to upload files into Google Drive Teams Folders by Multer.

What's Multer?

Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. It is written on top of busboy for maximum efficiency.

NOTE: Multer will not process any form which is not multipart (multipart/form-data).

Translations

This README is also available in others languages.

Installation

npm install --save multer-google-drive-teams-storage

Usage

const express = require('express');
const multer =  require('multer');
const { uuid } = require('uuidv4');
const { google } = require('googleapis');
const bodyparser = require('body-parser');

const GoogleStorage = require('google-drive-storage');

const auth = new google.auth.GoogleAuth({
    keyFile: './your-google-service-account-key-file.json',
    scopes: [
        'https://www.googleapis.com/auth/drive',
        'https://www.googleapis.com/auth/drive.file',
        'https://www.googleapis.com/auth/drive.appdata',
        'https://www.googleapis.com/auth/drive.readonly',
        'https://www.googleapis.com/auth/drive.metadata.readonly',
        'https://www.googleapis.com/auth/drive.metadata',
        'https://www.googleapis.com/auth/drive.photos.readonly'
    ],
});

const drive = google.drive({version: 'v3', auth });
const app = express();

app.use(bodyparser.urlencoded({ limit: '50mb', extended: false }))

const upload = multer({
    storage: GoogleStorage({
        drive: drive,
        driveId: '1iaudFygUYG_GKgkgKGJHGhjghjghjgtirtrduu',
        filename: function (req, file, callback) {

            const fileName = `${uuid()}-${file.originalname}`;

            callback(null, fileName);
        },
    })
});

app.post('/upload', upload.single('fileField'), (req, res) => {

    const {
        originalname,
        fileId
    } = req.file;

    res.send('File ' + originalname + ' with the id ' + fileId + ' are sent.');
});

API

GoogleDriveTeamsStorage accepts an options object. You need to specify a two required parameters in this object.

The following are the options that should be passaed to GoogleDriveTeamsStorage.

Key | Decription | Type | Required | ----------- | ---------- | ---- | -------- | drive | A drive object already authenticated provided by googleapis. | object | YES parent | The id of the folder what you want to put your file. | string | YES filename | A function with req, file and callback params to modifies the strategy of the filename. Default: original filename | function | NO

F.A.Q.

Can I use this storage to upload file outside a Team Drive?

Yes! But, it's depend of your authentication type. When you use the OAuth authentication you can upload files to you root Google Drive (My Drive).

What kind of authentication can I use?

You can authenticate to google through OAuth or through Service Account. In the example in the 'Use' section, I authenticated by Service Account. When you authenticate with Service Account, you need to create the Shared Drive (Team Drive) and grant permission for the Service Account to access it.

Licence

MIT