From a46cef75bc7e0b6ab0a34e24c3984383cc318933 Mon Sep 17 00:00:00 2001 From: ChenglongMa Date: Fri, 16 Oct 2020 10:44:56 +1100 Subject: [PATCH] Refine README --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- index.js | 2 +- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fa0b3f2..9e14a83 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,61 @@ -# skipper-gcstorage -A Skipper adapter for Google Cloud storage. +# [skipper emblem - face of a ship's captain](https://github.com/ChenglongMa/skipper-gcstorage.git) Google Cloud Storage Blob Adapter + + + +**Google Cloud Storage** adapter for receiving [upstreams](https://github.com/balderdashy/skipper#what-are-upstreams). Particularly useful for handling streaming multipart file uploads from the [Skipper](https://github.com/balderdashy/skipper) body parser. + +## Installation + +[![NPM](https://nodei.co/npm/skipper-gcstorage.png)](https://npmjs.org/package/skipper-gcstorage) + +``` +$ npm i skipper-gcstorage +``` + +## Usage + +```javascript +req.file('avatar') +.upload({ + // Required + adapter: require('skipper-gcstorage'), + bucket: 'existing_or_new_bucket_name', // Will create new one if no such bucket exists. + // Optional + projectId: 'GOOGLE_CLOUD_PROJECT', // Mandatory if `keyFilename` was specified. + keyFilename: 'GOOGLE_APPLICATION_CREDENTIALS', + bucketMetadata: {}, + maxBytes: 60000, + metadata: {}, + public: true +}, function whenDone(err, uploadedFiles) { + if (err) { + return res.serverError(err); + } + return res.ok({ + files: uploadedFiles, + textParams: req.params.all() + }); +}); +``` +Please don't check in your GCP credentials :) + +### NOTE + +1. `Skipper-GCStorage` will create new bucket if specified one does not exist. + 1. Assign bucket metadata into `bucketMetadata`. +2. Support multiple ways for **Authentication** + 1. Specify `projectId` AND `keyFilename`; + 2. `export` `GOOGLE_APPLICATION_CREDENTIALS` environment variable; + 3. Login with an eligible [service account](https://cloud.google.com/iam/docs/service-accounts); + 4. \*For more details, please refer to https://cloud.google.com/docs/authentication/production#command-line. +3. Use with [sails-hook-uploads](https://www.npmjs.com/package/sails-hook-uploads) for better results :) + + +## License + +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + +## Acknowledgement + +1. [Sails Skipper](https://github.com/sailshq/skipper) +2. [Skipper-S3](https://github.com/balderdashy/skipper-s3) \ No newline at end of file diff --git a/index.js b/index.js index 674dd94..a9b1b9a 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ const mime = require("mime"); * @param {Dictionary} globalOpts * @property {String?} projectId * @property {String?} keyFilename - * @property {String?} bucket + * @property {String} bucket * @property {Object?} bucketMetadata used to create non-existing bucket * @property {Number?} maxBytes * @property {Object?} metadata The metadata of gcs file