This sample demonstrates how to upload and download encrypted files in Google Storage using Cloud Functions.
Upload See file functions/gcf-upload-file/main.py for the code. The dependencies are listed in functions/gcf-upload-file/requirements.txt.
Download See file functions/gcf-download-file/main.py for the code. The dependencies are listed in functions/gcf-download-file/requirements.txt.
The functions triggers on http request.
Users upload an image to Storage to the auto generated path /<external ref uuid>/<encrypted uuid>/<filename>
and save the path and file reference in Cloud Datastore.
This sample comes with a Function and web-based UI for testing the function. To configure it:
- Create a Google Cloud Project using the Console
- Create billing account Console
- Enable the Cloud Functions API Console
- Enable the Cloud Datastore API Console
- Enable the Cloud Storage API Console
To test the sample:
- Download and install gcloud command line tool Console
- From function path functions/gcf-upload-file/ execute:
export FUNCTION_NAME="gcf-upload-file";
export BUCKET_NAME="poc-files";
export KIND_NAME="poc-files";
gcloud beta functions deploy ${FUNCTION_NAME} --entry-point execute --set-env-vars BUCKET_NAME=${BUCKET_NAME},DS_KIND=${KIND_NAME} --memory 128MB --runtime python37 --trigger-http;
- Return something like that:
Deploying function (may take a while - up to 2 minutes)...done.
availableMemoryMb: 128
entryPoint: execute
environmentVariables:
BUCKET_NAME: poc-files
DS_KIND: poc-files
httpsTrigger:
url: https://[zone]-[project id].cloudfunctions.net/gcf-upload-file
labels:
deployment-tool: cli-gcloud
name: projects/[project id]/locations/[zone]/functions/gcf-upload-file
runtime: python37
serviceAccountEmail: [service account email]
status: ACTIVE
timeout: 60s
updateTime: '2018-11-12T16:05:07Z'
versionId: '1'
- From function path functions/gcf-download-file/ execute:
export FUNCTION_NAME="gcf-download-file";
export BUCKET_NAME="poc-files";
export KIND_NAME="poc-files";
gcloud beta functions deploy ${FUNCTION_NAME} --entry-point execute --set-env-vars BUCKET_NAME=${BUCKET_NAME},DS_KIND=${KIND_NAME} --memory 128MB --runtime python37 --trigger-http;
- Return something like that:
Deploying function (may take a while - up to 2 minutes)...done.
availableMemoryMb: 128
entryPoint: execute
environmentVariables:
BUCKET_NAME: poc-files
DS_KIND: poc-files
httpsTrigger:
url: https://[zone]-[project id].cloudfunctions.net/gcf-download-file
labels:
deployment-tool: cli-gcloud
name: projects/[project id]/locations/[zone]/functions/gcf-download-file
runtime: python37
serviceAccountEmail: [service account email]
status: ACTIVE
timeout: 60s
updateTime: '2018-11-12T16:05:07Z'
versionId: '1'
- Edit example file examples/gcp-uploader.html, change post action to Cloud Functions uploader url.
- Edit example file examples/gcp-downloader.html, change post action to Cloud Functions downloader url.