Google Cloud Storage allows world-wide storage and retrieval of any amount of data at any time. You can use Google Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download.

Google Cloud Storage Connector 1.0.0

The Anypoint connector for Google Cloud Storage connector enables developers to use the Google Cloud Storage platform on MuleSoft Anypoint Runtime.

The Google Cloud Storage Connector is used to connect to the Google Cloud Storage. You can visit the Google Cloud Storage API here.

MuleSoft maintains the Premium connector under the Certified support policy.

Prerequisites

This document assumes that you are familiar with Mule, Anypoint Connectors, and Anypoint Studio. To increase your familiarity with Studio, consider completing a Anypoint Studio Tutorial. This page requires some basic knowledge of Mule Concepts, Elements in a Mule Flow, and Global Elements.

You will also require Anypoint Studio downloaded and installed on your development machine.

You will also need an account with Google Cloud Storage.

Hardware and Software Requirements

For hardware and software requirements, please visit the Hardware and Software Requirements page.

Compatibility

Software

Version

Mule Runtime

3.8.X all versions

Google Cloud Storage Library

0.9.2-beta

Java

1.7 and later

How to Install

You can install the connector in Anypoint Studio using the instructions in Installing a Connector from Anypoint Exchange.

How to Configure

To use the Google Cloud Storage connector in your Mule application, you must define a Global Element that can be used by one or many Google Cloud Storage message processor instances in an application or shared domain for connector user authentication and subsequent authorized use (read more about Global Elements).

Setting up Access to the Google Cloud Storage Service

The Google Cloud Storage service can be accessed once a connection is established with a service account.

Creating Global Element for the Google Cloud Storage Connector Configuration

  1. Click the Global Elements tab at the base of the Anypoint Studio canvas.

  2. On the Global Mule Configuration Elements screen, click Create.

  3. Type Google Cloud Storage into the Search bar.

  4. In the Choose Global Type wizard, expand Connector Configuration and select the Google Cloud Storage: JSON Service Account

  5. Click OK.

  6. Configure the parameters according to the table below.

    Field Description

    JSON Service Account File Location

    Enter the JSON location with your Google Cloud Storage credentials.

    Project ID

    Enter the corresponding project ID.

    Global Element Configuration

Required Connector Namespace and Schema

When designing your application in Anypoint Studio, when you drag the connector from the palette onto the Anypoint Studio canvas, Studio automatically populates the XML code with the connector namespace and schema location.

Namespace: http://www.mulesoft.org/schema/mule/google-cloud-storage
Schema Location: http://www.mulesoft.org/schema/mule/connector/current/mule-google-cloud-storage.xsd

Tip
If you are manually coding the Mule application in Studio’s XML editor or another text editor, define the namespace and schema location in the header of your Configuration XML, inside the <mule> tag.
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:connector="http://www.mulesoft.org/schema/mule/connector"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core
               http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/google-cloud-storage
               http://www.mulesoft.org/schema/mule/google-cloud-storage/current/mule-google-cloud-storage.xsd">

       <!-- put your global configuration elements and flows here -->
</mule>

Maven Dependency Information

For Maven dependency management, include this XML snippet in your pom.xml file.

<dependency>
  <groupId>org.mule.modules</groupId>
  <artifactId>google-cloud-storage-connector</artifactId>
  <version>1.0.0</version>
</dependency>

Common Use Cases

Upload Blob into Bucket

  1. Drag an File Endpoint into a new flow, and configure the file endpoint as follows:

    file inbound details
    Field Value

    Display Name

    File (or any other name you prefer)

    Path

    Path from which to pick the files

    Move to Directory

    (optional) Directory into which files are moved after being processed

    Connector Configuration

    (Optional) A configuration of a file connector

    add connector global element
  2. Drag the Google Cloud Storage connector onto the canvas, then click on the message processor and from beneath Basic Settings select the + symbol to add the Global Connector element.

    connector properties window
  3. Configure the connector settings, click on Test Connection to test that the connection configured works fine and then click on OK.

  4. Click on the Google Cloud Storage message processor that was dragged and select the Create Blob operation.

    configure settings message processor
  5. Set Blob Info Reference to #[flowVars['BlobInfo']]

  6. Add a Dataweave transformer after the file endpoint to create a BlobInfoPojo to pass on to the connector.

    edit current target dataweave
  7. Click on DataWeave message processor, and select edit and change the output to be Variable and enter BlobInfo as the variable name.

  8. In the dataweave Output click Define MetaData, In the new window that appears click on the add button, in the type id enter "BlobInfoPojo", Click ok, under type select Java, Under Data structure select Java, in the new window that appears search for BlobInfoPojo, select it and click ok.

    dataweave configuration
  9. Drag the originalFileName from the input tab to the name (under blobId) on the output pane.

  10. Double click on the bucket parameter under blobid, in the Dataweave editor hardcode the bucket name (i.e. bucket: "myBucketName").

  11. Since the connector returns a Blob object and the inbound endpoint does not require any response we can either transform the Object to Json with Dataweave or set the payload to an empty string (to avoid transformation exceptions).

  12. Run the project as a Mule Application (right-click project name, then select Run As > Mule Application).

  13. The Mule application should read any files in the path specified and should upload them to the Google Cloud Storage.

Resources