1.0.1 • Published 6 years ago

base64-cloudify v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

base64-cloudify

This module processes data URI string and uploads an image to Google Cloud Storage. Due to limited support (test here), for now, only .jpeg | .png extensions are supported by this module.

Prerequisites

NodeJS and npm are required.

Installation

To install please run npm install --save base64-cloudify

Description

This module exposes a function cloudify which is a promisified and callback-compatible NodeJS function that accepts the following parameters:

  • error - an Error instance;
  • options - an object with the following properties:
    • key - service account key;
    • projectId - project id;
    • bucketName - name of the existing bucket;
    • filenamePrefix - if omitted, defaults to 'img';
    • img - data URI string;
  • callback - optional; typical NodeJS function to be called with error and data arguments when upload completed.

After being invoken with proper arguments, the function saves an image to Google Cloud Storage under the name that consists of filenamePrefix-timestamp.extensionand immediately makes it public. Make sure the storage is configured properly

Return Value

returns a Promise that resolves to a string - url to access the uploaded image.

Example

const options = {
    key: require('../config/storage-service-account-sample.json'),
    projectId: 'sample-project',
    bucketName: 'sample_bucket',
    filenamePrefix: 'sampleImg',
    img: req.body.img
  };

cloudify(null, options)
   .then( url => res.status(200).send(url))

How to

Key

To get a key, please visit Google API Console, create a Project. Then on your project Dashboard click Enable APIS and Services button at the top-left part of your screen to enable Cloud Storage. Then through Credentials link (left side menu) create credentials => service account key and download it in JSON.

ProjectId

May be found on Google API Console in select-a-project menu.

Configure

Go to Google Cloud Platform dashboard => storage => buckets => name find menu editBucketPermissions - add members => storageObjectCreator and fill in the email of your service account from the key.

1.0.1

6 years ago

1.0.0

6 years ago