academind / firebase-cloud-functions-introduction Goto Github PK
View Code? Open in Web Editor NEWA miniseries introducing Firebase Cloud Functions (Also see: https://www.academind.com/learn/firebase/cloud-functions)
A miniseries introducing Firebase Cloud Functions (Also see: https://www.academind.com/learn/firebase/cloud-functions)
@maxschwarzmueller I'm getting a firebase deploy error when running the code with the onChange. Seems this is deprecated. I swapped it out for onFinalize
but that's not picking up the file changes (e.g. file upload). Please advise.
These are the things I had to change to get it to deploy correctly:
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.onFileChange= functions.storage.object().onFinalize(event => {
const object = event.data;
const bucket = object.bucket;
const contentType = object.contentType;
const filePath = object.name;
console.log('File change detected, function execution started');
if (object.resourceState === 'not_exists') {
console.log('We deleted a file, exit...');
return;
}
if (path.basename(filePath).startsWith('resized-')) {
console.log('THIS FILE HAS BEEN RENAMED ALREADY ');
return;
}
const ggg = new gcs() ;
const destBucket = ggg.bucket(bucket);
const tmpFilePath = path.join(os.tmpdir(), path.basename(filePath));
const metadata = { contentType: contentType };
return destBucket.file(filePath).download({
destination: tmpFilePath
}).then(() => {
return spawn('convert', [tmpFilePath, '-resize', '500x500', tmpFilePath]);
}).then(() => {
return destBucket.upload(tmpFilePath, {
destination: 'resized-' + path.basename(filePath),
metadata: metadata
})
});
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.