Skip to content

KelvinPac/LapitChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Automatically Generate Thumbnails

This sample demonstrates how to automatically generate thumbnails for each profile images that are uploaded to Firebase Storage for LapitChat App LapitChat App

alt tag

Functions Code

See file functions/index.js for the thumbnail generation code.

The thumbnail generation is performed using ImageMagick which is installed by default on all Cloud Functions instances. This is a CLI so we execute the command from node using the child-process-promise package. The image is first downloaded locally from the Firebase Storage bucket to the tmp folder using the google-cloud SDK.

In order to generate a Signed URL, a Service Account Key is required. A Signed URL grants public read or write access to the URL for a specified limited time.

The dependencies are listed in functions/package.json.

Trigger rules

The function triggers on upload of any file to your Firebase project's default Cloud Storage bucket.

Deploy and test

To deploy and test the sample:

  • Create a Firebase project on the Firebase Console and visit the Storage tab.
  • Clone this repo: git clone https://github.com/firebase/functions-samples.
  • Open this sample's directory: cd functions-samples/generate-thumbnail
  • Setup your project by running firebase use --add and select the project you had created.
  • Install dependencies in the functions directory: cd functions; npm install; cd -
  • Go to the Firebase Console, select the gear image > project settings > Service Accounts and click Generate New Private Key* to download a Service Account Key JSON document.
  • Add the JSON document to the Functions directory.
  • Replace cloud-functions-f199c-firebase-adminsdk-vn436-1699cb8c56.json with the name of the Service Account JSON document.
  • Deploy your project using firebase deploy
  • Go to the Firebase Console Storage tab and Create a profile_images folder then upload an image in the folder. After a short time an thumbnail image with the same name but a thumb_ prefix will be created in the same folder (make sure you refresh the UI to see the new file).
  • Go to the Firebase Console Database tab and child Users then child {user_uid} and the image and thumb_image has been updated contiaining the Signed URLs for both images.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published