Skip to content

Commit 100607a

Browse files
updated setup instructions for GCP, started experimenting with bluemix uploads
1 parent a9d5db3 commit 100607a

6 files changed

Lines changed: 32 additions & 13 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
samples
22
node_modules
33
keys
4+
src/gcp/keys
5+
src/bluemix/keys
6+
src/azure/keys
7+
src/aws/keys

README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ AWS - *Future*
4949
- Subscription based upload workers
5050
- Swap from proprietary libraries to base http
5151
- Leverage relevant CDNs to improve download performance
52+
- Parallel multi-part uploads (https://www.npmjs.com/package/s3)

src/bluemix/config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"project_id":"307972859230",
3+
"bucket_name":"image_api_307972859230",
4+
"keys": {
5+
"path":"./keys",
6+
"cloud_storage": {
7+
"path":"./../../keys/cloudStorage.json"
8+
},
9+
"cloud_functions": {
10+
"path":"./../../keys/functions.json"
11+
}
12+
}
13+
}

src/bluemix/experiments/upload.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@ let storage = new Storage.S3(config);
1313

1414
// Returns a Promise object which resolves to a stream.
1515
function uploadByURL(url, bucket, fileName) {
16-
return storage.putObject({
17-
18-
}).promise();
19-
20-
let file = bucket.file(fileName);
16+
//let file = bucket.file(fileName);
2117
return new Promise((resolve, reject) => {
2218
request(url)
2319
.on('response', (response) => { response.pause(); resolve(response); })
2420
.on('error', (reject));
25-
//.on('finish', ());
26-
}).then((response) => { return response.pipe(file.createWriteStream({ gzip: true })); }) // TODO: Restructure.
21+
}).then((response) => {
22+
return storage.putObject({ Bucket:bucket, Key:fileName, Body:response })
23+
.promise();
24+
})
2725
.catch((error) => { return { error }; }); // TODO: Add more detailed error handling. - statusCode etc.
2826
}
29-
// TODO: file.createResumableUpload
3027

3128
exports.upload = function (url) {
3229
return uploadByURL(url, storage.bucket(config.bucket_name), path.basename(url));
3330
};
34-
31+
/*
3532
function createTextFile(bucketName, itemName, fileText) {
3633
console.log(`Creating new item: ${itemName}`);
3734
return cos.putObject({
@@ -46,6 +43,7 @@ function createTextFile(bucketName, itemName, fileText) {
4643
console.error(`ERROR: ${e.code} - ${e.message}\n`);
4744
});
4845
}
46+
*/
4947

5048
/**
5149
*

src/gcp/README.MD

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ The base use case is the ability to upload remote images into a cloud storage bu
1919
- Resilience []
2020

2121
## Setup
22-
1. Create Project.
23-
2. Add Project_ID to config.json
22+
1. Create Project and add Project_ID to config.json
23+
2. Create a service account with access to upload Google Functions and save the key in keys/gcp_functions.json
24+
3. Create Bucket in Google Cloud Storage and update bucket_name in config.json
25+
4. Create a service account with write permissions to your google storage bucket and save the key in keys/gcp_storage.json
2426
TODO: add script to deploy.sh to add Project_ID to bucket name
2527

28+
2629
### Service Accounts
2730

2831
## Leads

src/gcp/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"keys": {
55
"path":"./keys",
66
"cloud_storage": {
7-
"path":"./keys/cloudStorage.json"
7+
"path":"./keys/gcp_storage.json"
88
},
99
"cloud_functions": {
10-
"path":"./keys/functions.json"
10+
"path":"./keys/gcp_functions.json"
1111
}
1212
}
1313
}

0 commit comments

Comments
 (0)