README
Google Cloud Storage Blob Adapter
Google Cloud Storage adapter for receiving upstreams. Particularly useful for handling streaming multipart file uploads from the Skipper body parser.
Installation
Option 1: NPM Package
$ npm i skipper-gcstorage
Option2: GitHub Package
$ npm i @chenglongma/skipper-gcstorage
Changelog
Ver 2.2.0
- Update dependencies to the latest version.
- sharp: 0.29.2, now it supports M1 chipset (thanks lahiruelectrily (github.com))
- mime: 3.0.0
Ver 2.1.0
Thanks jspark-gigworks (Anselmo Park) so much for his comments!
- Emit
writefile
event when finishing the job. - Support additional
CreateWriteStreamOptions
listed in https://googleapis.dev/nodejs/storage/latest/global.html#CreateWriteStreamOptions.
Ver 2.0.0
- Add
resize
options, which can compress the images before uploading.
Usage
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: '/path/to/GOOGLE_APPLICATION_CREDENTIALS.json',
bucketMetadata: {
location: 'us-west1',
}, // Refer to https://googleapis.dev/nodejs/storage/latest/global.html#CreateBucketRequest
maxBytes: 60000,
metadata: {},
public: true,
gzip: true,
// Other options in `CreateWriteStreamOptions`
// Refer to https://googleapis.dev/nodejs/storage/latest/global.html#CreateWriteStreamOptions
...CreateWriteStreamOptions,
resize: {
width: 500,
height: 500
}, // Refer to https://sharp.pixelplumbing.com/api-resize#resize
}, 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
Skipper-GCStorage
will create new bucket if specified one does not exist.- Assign bucket metadata into
bucketMetadata
.
- Assign bucket metadata into
- Support multiple ways for Authentication
- Specify
projectId
ANDkeyFilename
; export
GOOGLE_APPLICATION_CREDENTIALS
environment variable;- Login with an eligible service account;
- *For more details, please refer to https://cloud.google.com/docs/authentication/production#command-line.
- Specify
- Use with sails-hook-uploads for better results :)