Git Product home page Git Product logo

file-upload-gcloud-function's Introduction

Google Cloud Platform logo

Deploy and run

Preview

On my web development journey, one task I come across very often is uploading files(images, videos, etc) and making them accesible by some means to a frontend

The uploaded file will generally be made public using a url that is provided after it has been successfully uploaded and stored

Goal of this project

"Why should I always re-implement the same functionality across different backends?" I always asked myself. That's why I came up with a simple solution, why not a cloud function? It will be platform/backend agnostic and it doesn't come with all the hassle of setting up a dedicated backend

Why a cloud function?

I don't know

Initial steps

These are the steps I will follow for a beginning. It may change with time and requirements

  • send a post request to the function
  • the request should contain the asset/assets to be stored in base64 format
  • the request may also contain parameters to indicate in which platform/service the assets should be stored (digital-ocean, cloudinary, S3, firebase, gcloud, etc)

Note: in order for the tests to run properly, you'll have to deploy some of the sample functions:

gcloud functions deploy helloHttp --runtime [YOUR_RUNTIME] --trigger-http
gcloud functions deploy helloPubSub --trigger-topic $FUNCTIONS_TOPIC --runtime [YOUR_RUNTIME]
gcloud functions deploy helloGCS --runtime [YOUR_RUNTIME] --trigger-resource $FUNCTIONS_DELETABLE_BUCKET --trigger-event providers/cloud.storage/eventTypes/object.change
  • Replace [YOUR_RUNTIME] with the name of the runtime you are using. For a complete list, see the gcloud reference.

Run the tests

  1. Read and follow the prerequisites.

  2. Install dependencies:

     npm install
    
  3. Set the following environment variables:

     export GCF_REGION=us-central1
     export FUNCTIONS_TOPIC=[YOUR_PUBSUB_TOPIC]
     export FUNCTIONS_DELETABLE_BUCKET=[YOUR_CLOUD_STORAGE_BUCKET]  # will be deleted by tests!
    
  4. Run the tests:

     npm test
    

file-upload-gcloud-function's People

Contributors

exceldurant avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.