# gcloud-storage-api

> A wrapper around the google storage functions for upload (both upload and streaming) and delete.

Latest version **1.2.2** (published 2016-07-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install gcloud-storage-api
pnpm add gcloud-storage-api
yarn add gcloud-storage-api
bun add gcloud-storage-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2016-07-01 |
| First published | 2016-05-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Peter Chang |
| Maintainers | wahengchang |
| Keywords | google, storage, upload, promise, gcloud, file, streaming, local, api |

## Links

- npm: https://www.npmjs.com/package/gcloud-storage-api
- Repository: https://github.com/wahengchang/gcloud-storage-api
- Homepage: https://github.com/wahengchang/gcloud-storage-api#readme
- Issues: https://github.com/wahengchang/gcloud-storage-api/issues
- npm.io page: https://npm.io/package/gcloud-storage-api

## Dependencies (6)

- [gcloud](https://npm.io/package/gcloud.md) ^0.34.0
- [express](https://npm.io/package/express.md) ^4.13.4
- [url-valid](https://npm.io/package/url-valid.md) ^0.3.0
- [formidable](https://npm.io/package/formidable.md) ^1.0.17
- [underscore](https://npm.io/package/underscore.md) ^1.8.3
- [url-string-api](https://npm.io/package/url-string-api.md) ^1.0.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.2.2 (latest) — 2016-07-01
- 1.2.1 — 2016-06-21
- 1.2.0 — 2016-06-09
- 1.1.0 — 2016-05-26
- 1.0.0 — 2016-05-25

## README

# gcloud-storage-api 

An easy google storage tool to upload file and generate public link as return (both file uploading and buffer streaming).


A wrapper base on gcloud, which around the google storage functions for upload (both file uploading and streaming) and delete.[![NPM](https://nodei.co/npm/gcloud-storage-api.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/gcloud-storage-api)


## Install

```
$ npm install --save gcloud-storage-api
```

## Functions of this package:

```js
googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath)
googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer)
googleAPI.deleteStorageFile(url)
```


## Usage
To get the projectId and key.json, it is needed to Visit the Google Developers Console. There is the offical instruction from gcloud: https://www.npmjs.com/package/gcloud 


#### Initialization

Create a service account key on Google Cloud Console:

![alt tag](https://cloud.githubusercontent.com/assets/5538753/16215382/5228e5aa-3794-11e6-985d-bb579efe03a7.png)

Key type, select JSON, and then a service-key.json is generated and able to download:

![alt tag](https://cloud.githubusercontent.com/assets/5538753/16215545/ac4dd7a6-3795-11e6-80b7-defd9f334e72.png)

Paste the service-key to root of NODE project

![alt tag](http://gdriv.es/gpeter/desktop.png)

service-key.json 

![alt tag](http://gdriv.es/gpeter/sublime_.png)

Initializing gcloud 
```js
var googleAPI = require('gcloud-storage-api')
googleAPI.init('projectId',"service-key.json")
```

#### Upload local file 
- **googleAPI.formParsing** is a fomidable function which parsing local file with POST is multipart
- **googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath)** is a function that does local file uploading, respose the public link and resolve a promise.
```js
## Usage
app.post('/upload', googleAPI.formParsing, function(req, res, next) {

    var fileName = "path/to/"+req.uploadFile.name
    var fileLocalPath  = req.uploadFile.path
    var BUCKET_NAME = "yourbucket"

    googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath).then(function(result) {
        console.log("finished uploadLocalFile: "+result)
        res.send(result)
    },function(err){
        console.log(err)
    })
});
```


#### Upload Streaming/Buffer
- **fileName = "path/to/upload/abc.file"**
- **googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer)** is a function that does buffer uploading, respose the public link and resolve a promise.

```js
app.post('/streamupload', googleAPI.formParsing, function(req, res, next) {

    var fileName = "path/to/"+req.uploadFile.name
    var fileLocalPath  = req.uploadFile.path
    var BUCKET_NAME = "peterbucket"

    fs.readFile(fileLocalPath,function(err, buffer){
        googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer).then(function(result) {
            console.log("after googleAPI.deleteDownloadableFile: "+result)
            res.send(result)
        })
    })
});
```


#### Delete storage file
- **url = "https://storage.googleapis.com/yourbucket/path/to/upload/abc.file"**
- **googleAPI.deleteStorageFile(url)** is a function that deletes file on google storage.

```js
app.post('/delete', function(req, res, next) {
    var url = req.query.url
    googleAPI.deleteStorageFile(url).then(function(result) {
        console.log("after googleAPI.deleteStorageFile: "+result)
        res.send(result)
    })
});
```

## License


[MIT](http://vjpr.mit-license.org)

---
_Source: https://npm.io/package/gcloud-storage-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
