Backbench Docs
  • Introduction
  • Getting Started
    • BBLANG
    • Node
    • Python
    • Go
  • Backbench Features and UI workflow
  • API Reference
    • BBLANG
    • Node
    • Python
    • Go
  • 3rd Party Integrations
    • Login using Facebook
    • Login using Google
    • Login with Twitter
    • Login using LinkedIn
    • Connection with MongoDB
    • Connection with MySQL
    • Geo Location Integration
    • Integration with AWS S3
    • Integration with Google Cloud Storage
    • Integration with Razorpay
    • Integration with Stripe
    • Integration with Mailchimp
    • Integration with Segment
    • Sending Emails with SendGrid
    • Sending Emails with Mailgun
    • Sending SMS with Twilio
    • Sending Push Notification with Pushwoosh
  • Troubleshooting and support
    • CNAME Support
    • FAQS
    • Error Codes
  • Testing
Powered by GitBook
On this page
  • What You'll Need
  • Prerequisites
  • Adding Dependencies
  • Operation 1: Creating bucket.
  • Backend
  • Operation 2: Uploading file in a storage bucket
  • Backend
  • Operation 3: Listing objects in a storage bucket.
  • Backend
  • Operation 3: Deleting objects in a storage bucket.
  • Backend
  1. 3rd Party Integrations

Integration with Google Cloud Storage

PreviousIntegration with AWS S3NextIntegration with Razorpay

Last updated 6 years ago

What You'll Need

Backbench account - , the personal account will always remain free to use.

Google developer login- create an account and create an app on google developers from .

Prerequisites

  1. Setting up project: after creating a project in google developers, select Api’s and services under that library tab, you will find Api library for different categories, select storage under that select google cloud storage, you will have to click on enable button, this will enable google cloud storage to your project.

  2. Setting up environment variables: Create a via the Google Cloud Platform Console (The Cloud Storage JSON API must also be enabled.) and create a service account.

  • Once service account is created go to credentials page and download the credentials.

  • Now go to backbench platform and create a module with .json extension, say cloud.json. copy paste the downloaded credentials and save.

  • Now go to environment variable section of backbench and add a new environment variable with GOOGLE_APPLICATION_CREDENTIALS as name and value with the path of json file as ./cloud.json and hit on add.

Adding Dependencies

For nodejs only.

Create a module name package.json and paste the following code.

{
	"dependencies": {
		"@google-cloud/storage": "1.6.0"
	}
}

Operation 1: Creating bucket.

Backend

  1. Select +, in the upper right corner to create a Module. For example, say "google_create.js" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Replace PROJECT_ID (from google developers dashboard).

  4. Select save.

// Imports the Google Cloud client library
const Storage = require("@google-cloud/storage");

// Your Google Cloud Platform project ID
const projectId = "PRODUCT_ID";

// Creates a client
const storage = new Storage({
  projectId: projectId,
});

// The name for the new bucket
const bucketName = "my_bucket";

module.exports.endpoint= function(req,cb) {
// Creates the new bucket
storage
  .createBucket(bucketName)
  .then(() => {
    console.log("Bucket created.");
     cb(undefined,{d: "bucket created"});
  })
  .catch(err => {
    console.error("ERROR:", err);
  cb(err);

  }); 
};

Operation 2: Uploading file in a storage bucket

Backend

  1. Select +, in the upper right corner to create a Module. For example, say "Uploading_object.js" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Replace PROJECT_ID (from google developers dashboard).

  4. Select save.

// Imports the Google Cloud client library
const Storage = require("@google-cloud/storage");

// Your Google Cloud Platform project ID    
const projectId = "PROJECT_ID";

// Creates a client
const storage = new Storage({
  projectId: projectId,
});
// The name for the new bucket
const bucketName = "my_bucket";
const filename = "FILE_NAME";

module.exports.endpoint= function(req,cb) {
   storage
  .bucket(bucketName)
  .upload(filename)
  .then(() => {
    console.log("${filename} uploaded to ${bucketName}.");
  cb(undefined,{d: "file uploaded"}); 
  })
  .catch(err => {
    console.error("ERROR:", err);
    cb(err);
  });
};
cloudup:home(req) -> {
bb:http:put({
   url:'https://storage.googleapis.com/[BUCKET NAME]/[object name]',
   headers:{
   Content_Type:"application/json",
   Content_length: 0
   },
    auth:{   
    bearer:"[OAUTH2_TOKEN]"
    }
   })
}

//just a redirect handler
redirect:handler(req, url) -> {
    return {
        status: 302,
        headers: {
            Location: url
        }
    }
} 

Operation 3: Listing objects in a storage bucket.

Backend

  1. Select +, in the upper right corner to create a Module. For example, say "listing_object.js" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Replace PROJECT_ID (from google developers dashboard).

  4. Select save.

// Imports the Google Cloud client library
const Storage = require("@google-cloud/storage");
// Your Google Cloud Platform project ID
const projectId = "PROJECT_ID";
// Creates a client
const storage = new Storage({
  projectId: projectId, 
});
// The name for the new bucket
const bucketName = "my_bucket";
module.exports.endpoint= function (req, cb) {
storage
  .bucket(bucketName)
  .getFiles()
  .then(results => { 
    const files = results[0];
    console.log("Files:");
    files.forEach(file => {
      console.log(file.name);
          cb(undefined,files);
    });
   // cb(undefined, {data : results})
  })
  .catch(err => {
      cb({err: err})
    console.error("ERROR:", err);
  });
};
cloud:home(req) -> {

bb:http:get({

   url:'https://storage.googleapis.com/[BUCKET NAME]',
   headers:{
   Content_Type:"application/json",
   Content_length: 0
   },
    auth:{   
    bearer:"[OAUTH2_TOKEN]"
    }
   })
}
//just a redirect handler
redirect:handler(req, url) -> {
    return {
        status: 302,
        headers: {
            Location: url
        }
    }
} 

Operation 3: Deleting objects in a storage bucket.

Backend

  1. Select +, in the upper right corner to create a Module. For example, say "deleting.js" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Replace PROJECT_ID (from google developers dashboard).

  4. Select save.

// Imports the Google Cloud client library
const Storage = require("@google-cloud/storage");
// Your Google Cloud Platform project ID
const projectId = "PROJECT_ID";
// Creates a client
const storage = new Storage({
  projectId: projectId,
});
// The name for the new bucket
const bucketName = "my_bench";
const filename = "FILE_NAME";
module.exports.endpoint= function(req,cb) {
    storage
  .bucket(bucketName)
  .file(filename)
  .delete()
  .then(() => {
    console.log(“deleted.");
    cb(undefined, {d: "File Deleted"})
  })
  .catch(err => {
    console.error("ERROR:", err);
    cb(err);
  });
};
clouddel:home(req) -> {

bb:http:delete({
   url:'https://storage.googleapis.com/[BUCKET NAME/[object name]',
    auth:{
    bearer:"[OAUTH2_TOKEN]"
    }
   })
}

//just a redirect handler
redirect:handler(req, url) -> {
    return {
        status: 302,
        headers: {
            Location: url
        }
    }
} 
Sign Up
https://console.developers.google.com
Genomics-enabled project