Giter VIP home page Giter VIP logo

muggler's Introduction

Muggler

Muggler is a node.js module for using Google Drive API in a simplified way.

NOTE: Muggler process only multipart/form-data. Use attribute enctype='multipart/form-data' in form.

Before you start

Create project on Google Cloud Platform and enable Google Drive API.
Check this for step by step tutorial.

Getting started

Installation

$ npm install muggler --save

Requiring module

const config  = require('../path/to/secret/config.json');
const muggler = require('muggler')({
  email: config.client_email,
  key: config.private_key
});

Methods

listAll

app.get('/', function (req, res) {
  muggler.listAll({infolder: 'folderid'}, function (err, resp) {
    if (err) {
      console.log(err);
    }
    res.send(resp);
  })
})
  • infolder accepts 'string' and 'array' value only.
  • for root folder of drive use root as 'folderid'.
  • infolder: [folder1id, folder2id] will get files whose parent folder is either folder1 or folder2 that is, all files inside folder1 and folder2 will be in response.
// Response structure
{
  status: 'status of operation',
  mug: [
    {
      kind: 'kind of file',
      id: 'id of file',
      name: 'name of file',
      mimeType: 'type of file'
    },
    {
      kind: 'kind of file',
      id: 'id of file',
      name: 'name of file',
      mimeType: 'type of file'
    }
  ]
}

upOne

app.post('/', function (req, res) {
  muggler.upOne({fromfield: 'fieldname', infolder: 'folderid'}, req, function (err, resp) {
    if (err) {
      console.log(err);
    }
    res.send(resp);
  })
})
  • fromfield accepts 'string' value only.
  • fieldname should be name of the input field which will accept file in form.
  • infolder accepts 'string' and 'array' value only.
  • for root folder of drive use root as 'folderid'.
  • infolder: [folder1id, folder2id] will upload file to folder1 and folder2 both with same id.
// Response structure
{
  file: {
    fieldname: "name of input field",
    originalname: "original name of file",
    encoding: "encoding type",
    mimetype: "type of file",
    destination: "temporary destination",
    filename: "changed name of file",
    path: "tempporary location of file",
    size: 'size of file'
  },
  status: "status of operation",
  mug: {
    id: "id of file",
    name: "name of file",
    mimeType: "type of file",
    size: 'size of file',
    parents: [
      "parent folder id"
    ],
    url: "url of file"
  },
  body: {
    otherFormField: "value in field"
  }
}

delOne

app.post('/', function (req, res) {
  muggler.delOne({fileid: 'id of file'}, req, function (err, resp) {
    if (err) {
      console.log(err);
    }
    res.send(resp);
  })
})
  • fileid accepts 'string' value only.
// Response structure
{
  status: "status of operation",
  mug: []
}

Something to note

  • Service Account has its own Google Drive storage so files uploaded using Muggler will not be there in your own Google Drive.
  • Create folder in your Google Drive manually and share it with Service Account using client_email.
    • Open that folder and looking into its URL for its ID.
    • Files uploaded using Muggler into this folder will be visible in your own Google Drive now but storage of Service Account's Google Drive will be used. That is, originally file is created in Service Account's Google Drive as it is uploaded by Service Account but its reference is visible in your own Google Drive also because folder is shared.
    • If you manually delete any file from this shared folder then it will just delete the reference and original file will remain unaffected. To delete that file permanently use Service Account that is, using Muggler.

muggler's People

Contributors

riuandg5 avatar

Stargazers

 avatar

Watchers

James Cloos 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.