Firebase Cloud Functions - Resizing Images after Upload

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ต.ค. 2024

ความคิดเห็น • 121

  • @romainrouiller4889
    @romainrouiller4889 5 ปีที่แล้ว +37

    the entire code in order change the image name , here : ( I fixed the deprecated issues and other stuff, normally its working)
    const functions = require('firebase-functions')
    const { Storage } = require('@google-cloud/storage');
    const projectId = 'YOUR FIREBASE PROJECT ID';
    let gcs = new Storage ({
    projectId
    });
    const os = require('os');
    const path = require('path');
    exports.onFileChange = functions.storage.object().onFinalize(event => {
    console.log(event);
    const bucket = event.bucket;
    const contentType = event.contentType;
    const filePath = event.name;
    console.log('file detected')
    if(path.basename(filePath).startsWith('renamed-')){
    console.log('already renamed this file')
    return;
    }
    const destBucket = gcs.bucket(bucket);
    const tmpFilePath = path.join(os.tmpdir(), path.basename(filePath));
    const metadata = { contentType : contentType }
    return destBucket.file(filePath).download({
    destination : tmpFilePath
    }).then(() => {
    return destBucket.upload(tmpFilePath, {
    destination:'renamed-'+ path.basename(filePath),
    metadata: metadata
    })
    })
    });

  • @Joshca4
    @Joshca4 6 ปีที่แล้ว +91

    onChange is not a valid method anymore, instead i use onFinalize that seems work the same, also if you are folowing the video and typing the code yourself in 11:35 you no longer have to access event.data because onFinalize doesnt have that object, instead use const bucket = event.bucket const contentType = event.contentType const filePath = event.name directly and it should work.

    • @AHRienks
      @AHRienks 6 ปีที่แล้ว +3

      using onFinalize instead of onChange does not log the deletion of files, it seems!?

    • @ricklee128
      @ricklee128 6 ปีที่แล้ว +6

      you have to use onDelete and make another function

    • @brent5920
      @brent5920 6 ปีที่แล้ว +7

      You will need to use this function and then run 'firebase deploy' again to upload again to FIrebase, then add and re-delete the file you uploaded and make sure the drop down is set to "all functions" you will see a function for onFileDelete.
      exports.onFileDelete = functions.storage.object().onDelete(event => {
      console.log(event);
      return;
      });

    • @balance4432
      @balance4432 6 ปีที่แล้ว +1

      Thanks for these tips. I'm following along now and also ran into this issue.

    • @garychan1967
      @garychan1967 6 ปีที่แล้ว

      My code has issues at 19:29 of video. ONe moment... I will post image and github repo...

  • @tropicalverktaki
    @tropicalverktaki 5 ปีที่แล้ว +5

    I had some issues doing this in 2019. Couple of things that needs to be changed:
    const { Storage } = require('@google-cloud/storage');
    const gcs = new Storage({
    projectId: ''
    });
    You can get the project id by going to Project Settings on your Firebase dashboard.
    I also had to force Firebase Functions to run Node 8 by updating functions/package.json with the engines property.
    ...
    "engines": {
    "node": "8"
    },
    ...

    • @laurahenn3626
      @laurahenn3626 5 ปีที่แล้ว +2

      Thanks, saved me in 2019 also

  • @danielbachmann1050
    @danielbachmann1050 4 ปีที่แล้ว

    Very small tip: If you're wondering why you can't access the created file (renamed or resized) in the Firebase Storage Console, you have to create an access token for the file by selecting it and use the link in the right panel (second Drawer, which is "Dateispeicherort" in german, so maybee "Filepath").

  • @paymankhayree8552
    @paymankhayree8552 5 ปีที่แล้ว +1

    hi can't get 'child-process-promise' to work. when declare it in "require" method i get the warning "could not find a declaration file for module". I have installed it. it threw lots of warnings though

  • @rickyu1978
    @rickyu1978 6 ปีที่แล้ว

    Great cloud functions videos. Keep them coming please.

    • @academind
      @academind  6 ปีที่แล้ว

      Makes me really happy to read that you like it, the next one will come on Monday!

  • @temitopejunior
    @temitopejunior 6 ปีที่แล้ว

    Biggest fan here - can't wait to go through this one too!!!!

    • @academind
      @academind  6 ปีที่แล้ว

      Thank you so much, I really hope that you will like the video :)

  • @rujalduwal6847
    @rujalduwal6847 3 ปีที่แล้ว

    Error: Your project fb-cloud-function-demo-2ae3c must be on the Blaze (pay-as-you-go) plan to complete this command. Required API cloudbuild.googleapis.com can't be enabled until the upgrade is complete. To upgrade, visit the following URL:
    unable to deploy do I need to pay for it?

  • @iankurbiswas
    @iankurbiswas 6 ปีที่แล้ว +12

    How to get the downloadURL of the compressed image?

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode 6 ปีที่แล้ว

    Great stuff Max. A few changes since this video published:
    Good note from Jose discussing onChange and replacing with onFinalize.
    Also, gcs has changed usage has changed (github.com/googleapis/nodejs-storage/releases/tag/v2.0.0)
    const {Storage} = require('@google-cloud/storage');
    const gcs= new Storage();
    I also suggest checking out npm sharp vs ImageMagick:
    (www.npmjs.com/package/sharp)
    const sharp = require('sharp');
    const fs = require('fs-extra');
    return destBucket.file(filePath).download({
    destination: tmpFilePath
    }).then(() => {
    sharp(path.basename(filePath))
    .resize(500)
    .toBuffer()
    .then(data => {
    console.log(data);
    fs.writeFileSync(path.basename(filePath), data);
    return destBucket.upload(tmpFilePath,{
    destination: 'renamed-' + path.basename(filePath),
    metadata: metadata
    });
    })

  • @georgevilau7321
    @georgevilau7321 5 ปีที่แล้ว +4

    First of all great content! and second of all: if we are relying on getDownloadURL() to retrive the URL for the uploaded picture in our Angular project, how would we get the URL for the newly created image (resized-image) in order to use that instead of the first one? Thank you!

  • @JonsonNcube
    @JonsonNcube 4 ปีที่แล้ว +1

    In case you are getting this error:
    Error: Error occurred while parsing your function triggers.
    TypeError: Class constructor Firestore cannot be invoked without 'new'
    user this:
    const { Storage } = require('@google-cloud/storage');
    const gcs = new Storage()

  • @hanojb6844
    @hanojb6844 5 ปีที่แล้ว +1

    const gcs = require('@google-cloud/storage')() not support type funcation ??

  • @josephnkoro8429
    @josephnkoro8429 5 ปีที่แล้ว +4

    onChange is deprecated for firebase latest version.. So please and update of the video will help.. As well include how to retrieve the images

  • @one99one
    @one99one 5 ปีที่แล้ว

    Hi Maximilian, thank you for your videos. I have a question if you could answer.
    Many are suggesting to use Node.js for Firebase Cloud Functions. Why is this? I mean, couldn't I just use Vue.js with firebase-tools package for that?
    Or is it that with Node.js you have more functionalities like Android LED Notifications (if that was a requirement) ? Thank you in advance.

  • @kirangouds
    @kirangouds 6 ปีที่แล้ว

    This ImageMagic is so crazy.

  • @MarsTheProgrammer
    @MarsTheProgrammer 5 ปีที่แล้ว +3

    This is very dated and doesn't work in 2019... im getting a "cloud storage trigger bucket not found" error

    • @jefersonjoelpomachoque7540
      @jefersonjoelpomachoque7540 3 ปีที่แล้ว

      Hola mano, pude resolver ese problema con los comentarios de arriba.
      Para ello borra la linea del require de doble parentesis y reemplazalo por lo siguiente:
      const { Storage } = require('@google-cloud/storage');
      const projectId = 'Your ID'
      let gcs = new Storage ({
      projectId
      });
      Como dicen, el onChange esta obsoleto: onChange is not a valid method anymore, instead i use onFinalize that seems work the same
      const bucket = event.bucket
      const contentType = event.contentType
      const filePath = event.name
      Y mas abajo hay un if usando el object, cambialo por "event" como arriba.
      Gracias a las personas: "Amr Abo Elenin" y "Jose Antonio Canizales"

  • @jordan5253
    @jordan5253 5 ปีที่แล้ว

    Thank you very much this video it is actually really helpful

    • @academind
      @academind  5 ปีที่แล้ว

      Happy to read that Jordan, thank you for your comment!

  • @hugovallezinzun
    @hugovallezinzun 5 ปีที่แล้ว +3

    is there a way to get the download URL from the new image after the function uploads it

    • @Zelo246
      @Zelo246 4 ปีที่แล้ว

      i think you can replace the original file instead of getting the resized image URL and update the item in db

  • @miguelstevens3042
    @miguelstevens3042 2 ปีที่แล้ว

    Has anyone achieved dealing with this newly created file in Vue, for example? The client doesn't know when the server will be ready, how can we update Vue to show the resized image when it's ready?

  • @viplav76
    @viplav76 5 ปีที่แล้ว

    Any idea of how to create a Firebase Cloud Function to send a text string to Google DialogFlow V2 Standard Edition & obtaining back a response object/JSON in Firebase. Eventually to display on the Firebase Web Page?

  • @mgs_4k198
    @mgs_4k198 6 ปีที่แล้ว

    Hello, it seems the onChange event has been deprecated on Firebase
    firebase.google.com/docs/functions/beta-v1-diff
    which event would you suggest to use instead?

  • @aroan9532
    @aroan9532 6 ปีที่แล้ว

    i have the problem, that in my bucket there is no resource State. What can i use instead of this to check if the file exist?

  • @mycloudvip
    @mycloudvip 4 ปีที่แล้ว

    Hi There ... I'm one of your students at Udemy... Signed up for your Vue.js course... I'm also becoming familiar with firebase functions... I already tried the plugin which resizes the images after they are uploaded... The ONLY issue though, is that the function is failing... I tried to upload a single GIF file (7mb) size and then create a thumb for it... I get a message in the logs... that the function timed out after 60000 ms so the thumbnail image 200x200 was NEVER created... What can I do to solve this? Thanks and KEEP making great content.

  • @ThorBSN
    @ThorBSN 6 ปีที่แล้ว

    Is it possible to upload to a local dir? I can't get it to work with: axios.post('/users', fd)

  • @isurubandara899
    @isurubandara899 3 ปีที่แล้ว

    Hello can i run NFSW js which is explicit content detect model on cloud function?

  • @PMANOBRE
    @PMANOBRE 6 ปีที่แล้ว +4

    Hi max. Are you thinking to do a course on firebase, which includes the new db firestore, firestorage and cloud functions?

    • @academind
      @academind  6 ปีที่แล้ว

      I actually do not have any concrete plans to create such a course right now, but that might change in the future.

  • @myhdpicture
    @myhdpicture 4 ปีที่แล้ว

    To preview images, Firebase requires an access token (Click on the uploaded preview and scroll down, it's on the right side in a small font). This token is auto generated if you upload the image via Firebase, but not via Nodejs. I managed to fix this by using a module to generate an UUID and nest it in the metadata.
    Full code looks like this:
    const functions = require("firebase-functions");
    const { Storage } = require("@google-cloud/storage");
    const os = require("os");
    const path = require("path");
    const projectId = "@@@#";
    let gcs = new Storage({
    projectId
    });
    const spawn = require("child-process-promise").spawn;
    const uuidv4 = require("uuid/v4");
    const uuid = uuidv4();
    exports.onFileChange = functions.storage.object().onFinalize(async event => {
    const bucket = event.bucket;
    const contentType = event.contentType;
    const filePath = @t;
    console.log("File change detected, function execution started");
    if (path.basename(filePath).startsWith("resized-")) {
    console.log("We already renamed that file!");
    return;
    }
    const destBucket = gcs.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', '100x100', tmpFilePath]);
    }).then(() => {
    return destBucket.upload(tmpFilePath, {
    destination: 'resized-' + path.basename(filePath),
    metadata: {
    metadata: {
    firebaseStorageDownloadTokens: uuid
    }
    }
    })
    });
    });
    Note: The 'if' statement used to verify the file delete is not included yet, needs to be in another function as the one in the video is deprecated. However, this code worked fine so far. Hope this helps!

  • @moushufpradhan
    @moushufpradhan 4 ปีที่แล้ว

    Is it true that in contrast to earlier times, deployment of Firebase Cloud Functions requires a Blaze plan now? (for Node 10x environment)

    • @UnbiasedEverybody54
      @UnbiasedEverybody54 3 ปีที่แล้ว

      Yes I just figured that too! Did you get to use some other option to do this other than the firebase? Or did you just get Blaze? :D

  • @jcmargentina
    @jcmargentina 4 ปีที่แล้ว

    some why ... everything is working fine with the updates in the comments, ... BUT ... once in Storage menu in firebase console, ... if I click the renamed file ... the content is not preview ... is like is not an image or something like that. The renamed file size and metadata is the same as the original one, but the content is not previewed. Whats wrong here?

    • @myhdpicture
      @myhdpicture 4 ปีที่แล้ว

      To preview images, Firebase requires an access token (Click on the uploaded preview and scroll down, it's on the right side in a small font). This token is auto generated if you upload the image via Firebase, but not via Nodejs. I managed to fix this by using a module to generate an UUID and nest it in the metadata.
      Full code looks like this:
      const functions = require("firebase-functions");
      const { Storage } = require("@google-cloud/storage");
      const os = require("os");
      const path = require("path");
      const projectId = "#YOUR#PROJECT#ID#";
      let gcs = new Storage({
      projectId
      });
      const spawn = require("child-process-promise").spawn;
      const uuidv4 = require("uuid/v4");
      const uuid = uuidv4();
      exports.onFileChange = functions.storage.object().onFinalize(async event => {
      const bucket = event.bucket;
      const contentType = event.contentType;
      const filePath = event.name;
      console.log("File change detected, function execution started");
      if (path.basename(filePath).startsWith("resized-")) {
      console.log("We already renamed that file!");
      return;
      }
      const destBucket = gcs.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', '100x100', tmpFilePath]);
      }).then(() => {
      return destBucket.upload(tmpFilePath, {
      destination: 'resized-' + path.basename(filePath),
      metadata: {
      metadata: {
      firebaseStorageDownloadTokens: uuid
      }
      }
      })
      });
      });
      Note: The 'if' statement used to verify the file delete is not included yet, needs to be in another function as the one in the video is deprecated. However, this code worked fine so far. Hope this helps!

  • @ahmadnabeel2847
    @ahmadnabeel2847 6 ปีที่แล้ว

    getting this error:
    ChildProcessError: `convert /tmp/000000.png -resize 300*300 /tmp/000000.png` failed with code 1
    at ChildProcess. (/user_code/node_modules/child-process-promise/lib/index.js:132:23)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:920:16)
    at Socket. (internal/child_process.js:351:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:509:12)

    • @ahmadnabeel2847
      @ahmadnabeel2847 6 ปีที่แล้ว

      on this line return spawn('convert', [tmpFilePath, '-resize', '300*300', tmpFilePath]);

  • @MarlonEnglemam
    @MarlonEnglemam 4 ปีที่แล้ว +2

    Anyone has any idea on how to create a cloud function that will delete images after 24 hours? (Just like Snapchat and Instagram stories)

    • @sai_k_ganesh
      @sai_k_ganesh 4 ปีที่แล้ว

      write a settimeout() function for 24 hours and code to delete the image.. thats it .. cheers

    • @klutch4198
      @klutch4198 3 ปีที่แล้ว

      You have to run a cron job! set timeout will NOT work. timers don't run unless the component is mounted.

  • @Josemirab696
    @Josemirab696 5 ปีที่แล้ว

    any way to resize all the images in my firebase storage and not only the ones that i just uploaded?

  • @fotios4902
    @fotios4902 4 ปีที่แล้ว

    @ 02:25 you can also do:
    firebase login:ci

  • @avirosenberg
    @avirosenberg 6 ปีที่แล้ว

    Alright can I make action that Firebase to upload automatic from a folder on the computer to the Firebase storage and be there only for 5 minutes and then it should be deleted so I so I mean I should have a folder on my desktop that this folder is sync with my Firebase and Evie images going into the folder to be open. O matic to firebase-storage and should be deleted after 5 minutes from the Firebase storage

  • @MrWormBeast
    @MrWormBeast 6 ปีที่แล้ว +1

    Hi max, great tuts. but im cant find the way to use a bucket('bucketname') in my storage

  • @sugandhasingh3833
    @sugandhasingh3833 2 ปีที่แล้ว

    how I can change RGB image into grayscale image after upload?

  • @rauzanfikri9523
    @rauzanfikri9523 6 ปีที่แล้ว +1

    Hi How to load the image from inside folder ?

  • @avinashgardas974
    @avinashgardas974 6 ปีที่แล้ว

    Thanks bro! It helped me a lot :)

    • @academind
      @academind  6 ปีที่แล้ว

      Very happy to read that Avinash, thank you for your comment!

    • @avinashgardas974
      @avinashgardas974 6 ปีที่แล้ว

      You're welcome, I actually wanted to implement the exact same functionality and now I can see it in action.

    • @ethanherbst604
      @ethanherbst604 6 ปีที่แล้ว

      @Academind
      Deploy returns "Error: "onChange" is now deprecated, please use "onArchive", "onDelete", "onFinalize", or "onMetadataUpdate".
      What can we use for an alternate to "onChange"?

    • @avinashgardas974
      @avinashgardas974 6 ปีที่แล้ว

      Yeah I too got the same issue, I think onArchive should be used instead of onChange

    • @ethanherbst604
      @ethanherbst604 6 ปีที่แล้ว

      onArchive does not work for the function i am looking for, what worked for me was installing the older versions so that i could use the onChange function.
      npm install --save-exact firebase-functions@0.8.1
      npm install --save-exact firebase-admin@5.8.2
      and
      then you have to install the correct eslint package
      it should still give you an error but the solution is below...
      stackoverflow.com/questions/46530361/cloud-functions-for-firebase-error-400-change-of-function-trigger-type-or-eve

  • @oteorico5466
    @oteorico5466 6 ปีที่แล้ว

    I LOVE YOU, HOLLY SHIT, YOUR CHANNEL IS THE BEST

    • @academind
      @academind  6 ปีที่แล้ว

      Wow, that's really amazing to hear Romario, thank you so much! :)

  • @introvertedperson23
    @introvertedperson23 2 ปีที่แล้ว

    Error: "onChange" is now deprecated, please use "onArchive", "onDelete", "onFinalize", or "onMetadataUpdate".

  • @Adam-pl1jj
    @Adam-pl1jj 6 ปีที่แล้ว

    Deploy returns "Error: "onChange" is now deprecated, please use "onArchive", "onDelete", "onFinalize", or "onMetadataUpdate".
    What one should we be using now?

    • @srinivasjagadeesh6562
      @srinivasjagadeesh6562 6 ปีที่แล้ว +3

      I also faced similar problem, i used onFinalize - which basically responds to successful creation of object, onMetaUpdate - which responds to any changes to the existing object (I am still playing around)

    • @newtoninstrumentcompany1473
      @newtoninstrumentcompany1473 6 ปีที่แล้ว

      ditto

  • @andreip.8321
    @andreip.8321 2 ปีที่แล้ว

    Hm... Isn't there a better way to filter S3 file uploads? Because in your example, the function is still executed when resized images are created, if just returns in the if... but you're still billed for these invocations :) So it's like 50% of these function executions are early returns, but you're still paying for those.

  • @Ayrix06
    @Ayrix06 2 ปีที่แล้ว

    Bester Mann

  • @DeepakKumar-ik1sv
    @DeepakKumar-ik1sv 6 ปีที่แล้ว

    hi, i am new to cloud function can help me...i wanna delete user form firebase when data of user is delete from firebase

    • @DeepakKumar-ik1sv
      @DeepakKumar-ik1sv 6 ปีที่แล้ว

      thanks in advance reply to dk.904420@gmail.com

  • @Bastric91
    @Bastric91 4 ปีที่แล้ว

    child-process-promise not working... I have error xD Only when I cut require with spaw then Deploying..

  • @Zelo246
    @Zelo246 4 ปีที่แล้ว

    Thank you so much

  • @lxsedov
    @lxsedov 6 ปีที่แล้ว

    18:30 you do retrigger the function, that check only prevents executing the rest, but the function is triggered anyway, its cloud storage issue

  • @Ashdude9415
    @Ashdude9415 6 ปีที่แล้ว

    Is it possible to run a python file in firebase storage using firebase cloud functions????

    • @academind
      @academind  6 ปีที่แล้ว

      There certainly is some way of doing this, yes. I haven't tried it and I wouldn't expect it to be easy/ straightforward though. It's certainly not a built-in functionality

  • @Raudel537
    @Raudel537 4 ปีที่แล้ว

    If anyone else found an error like "MetadataLookupWarning: received unexpected error = URL is not defined code = UNKNOWN ", just update node version to 10 on package,json

  • @heyyy4987
    @heyyy4987 6 ปีที่แล้ว +1

    Firebase Cloud Functions its the same Lambda Amazon? tanks

    • @academind
      @academind  6 ปีที่แล้ว

      Yeah, it's pretty comparable but there are some differences. In general though, both is about running code on demand in the cloud

  • @rahunn8729
    @rahunn8729 5 ปีที่แล้ว

    Line const gcs = require('@google-cloud/storage')(); returns error: typeerror: require(...) is not a function
    Suggest solution

    • @claudiotormen759
      @claudiotormen759 5 ปีที่แล้ว

      just remove the last parenthesis (). like this "const gcs = require('@google-cloud/storage');"

  • @ptrchovan
    @ptrchovan 5 ปีที่แล้ว

    Hi Max. Are you on udemy with firebase functions?

    • @academind
      @academind  5 ปีที่แล้ว

      No, I don't have a Udemy course on Firebase, but "some" other courses ;) => academind.com/learn/

  • @muslim_travel
    @muslim_travel 6 ปีที่แล้ว +1

    Failed to configure trigger GCS Bucket. Anyone has this same problem??????????????

    • @raffibags
      @raffibags 6 ปีที่แล้ว

      object should just be set to event - not event.data. That worked for me.

  • @brent5920
    @brent5920 6 ปีที่แล้ว

    Unrecognized token in source text.
    At line:1 char:20
    + npm install --save

  • @hermanomark
    @hermanomark 6 ปีที่แล้ว

    I'm encountering a problem @19:27
    ```
    $firebase deploy
    === Deploying to 'fb-cloud-functions-demo-aaf09'...
    i deploying functions
    Running command: npm --prefix "%RESOURCE_DIR%" run lint
    > functions@ lint C:\Users\markhermano\Desktop\firebase-cloud-functions\functions
    > eslint .
    C:\Users\markhermano\Desktop\firebase-cloud-functions\functions\index.js
    25:2 warning Arrow function expected no return value consistent-return
    ✖ 1 problem (0 errors, 1 warning)
    + functions: Finished running predeploy script.
    i functions: ensuring necessary APIs are enabled...
    + functions: all necessary APIs are enabled
    i functions: preparing functions directory for uploading...
    Error: Error occurred while parsing your function triggers.
    TypeError: require(...) is not a function
    at Object. (C:\Users\markhermano\Desktop\firebase-cloud-functions\functions\index.js:2:45)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at C:\Users\markhermano\AppData\Roaming
    pm
    ode_modules\firebase-tools\lib\triggerParser.js:21:11
    at Object. (C:\Users\markhermano\AppData\Roaming
    pm
    ode_modules\firebase-tools\lib\triggerParser.js:75:3)
    ```
    Here is my code(index.js):
    ```
    const functions = require('firebase-functions');
    const gcs = require('@google-cloud/storage')();
    const os = require('os');
    const path = require('path');
    // // Create and Deploy Your First Cloud Functions
    // // firebase.google.com/docs/functions/write-firebase-functions
    //
    exports.onFileChange = functions.storage.object().onFinalize(event => {
    // response.send("Hello from Firebase!");
    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 (path.basename(filePath).startsWith('renamed-')) {
    console.log('We already renamed that file');
    return;
    }
    const destBucket = gcs.bucket(bucket);
    const tmpFilePath = path.join(os.tmpdir(), path.basename(filePath));
    const metadata = { contentType: contentType };
    return destBucket.file(filePath).download({
    destination: tmpFilePath
    }).then(() => {
    return destBucket.upload(tmpFilePath, {
    destination: 'renamed-' + path.basename(filePath),
    metadata: metadata
    })
    });
    });
    ```
    Could somebody help me!

    • @Viafoci
      @Viafoci 5 ปีที่แล้ว

      did you see Amr Abo Elenin 's comment above? this fixed the require is not a function for me...

  • @hackerbf8160
    @hackerbf8160 4 ปีที่แล้ว

    onChange is deprecated, should be changed to onFinalize now

  • @reddevil3217
    @reddevil3217 6 ปีที่แล้ว

    Hi there, how to resize image as square ? ignore ratio

    • @jamiecurnow9742
      @jamiecurnow9742 6 ปีที่แล้ว +1

      This will crop square 300x300 px image from the center of the original:
      return spawn('convert', [tempFilePath, '-gravity', 'center', '-crop', `300x300+0+0`, tempFilePath], {capture: ['stdout', 'stderr']})

  • @sachinrakibe8375
    @sachinrakibe8375 4 ปีที่แล้ว

    Please Make video on to resize video

  • @axea4554
    @axea4554 6 ปีที่แล้ว

    Tried to make a telegram bot with firebase functions as webhooks endpoint. When you write to bot in telegram client, telegram send a outgoing webhooks to function, function/bot make its work and then need to send a http request to telegram back, but ahhh... Need to upgrade the billing plan :( :D

  • @joshrochon6243
    @joshrochon6243 6 ปีที่แล้ว

    Firstly, this video is awesome. So thanks! On a diff note, would you consider adding some notes to the video? Such as the comment left by jose Antonio and also on account that onChange no longer exists in favour of other trigger methods now available, such as onDelete. If you look for object.resourceState you won't find it. No longer exists. You can check out the github conversation here: github.com/firebase/firebase-functions/issues/255.

  • @omarelsawy7562
    @omarelsawy7562 6 ปีที่แล้ว

    ChildProcessError when resize image

  • @mrtrader3661
    @mrtrader3661 ปีที่แล้ว

    it is not free to use functions!

  • @AbhishekKumar-mq1tt
    @AbhishekKumar-mq1tt 6 ปีที่แล้ว

    Thank U for this awesome video .can u thing to start full project series with vuejs express and mongodb

    • @academind
      @academind  6 ปีที่แล้ว

      Thanks a lot for your great feedback Abhishek!

  • @brianrathbone6046
    @brianrathbone6046 4 ปีที่แล้ว

    storage 8:28

  • @mabuhaypinoy
    @mabuhaypinoy 6 ปีที่แล้ว

    Love this tutorial. But onChange method was deprecated. Follow this new tutorial from Google for updated code. firebase.google.com/docs/storage/extend-with-functions#download_transform_and_upload_a_file

  • @paktechie2313
    @paktechie2313 6 ปีที่แล้ว

    Bro your accent plzzzzzzzzzzzzzzzzz

    • @academind
      @academind  6 ปีที่แล้ว +2

      It is what it is, sorry.

    • @paktechie2313
      @paktechie2313 6 ปีที่แล้ว

      Okay, can you tell me how to read the downloaded file if it is a text file?

    • @steveharrington5872
      @steveharrington5872 5 ปีที่แล้ว +2

      @@academind Max, you do a great job and have a great command of English! Good for you! Most people wouldn't have the boldness, the talent and the skill set to undertake any of this.

  • @piperskylar64
    @piperskylar64 5 ปีที่แล้ว

    waste of time

  • @nicolasmorin9539
    @nicolasmorin9539 4 ปีที่แล้ว

    Very very badly explained...too fast, too much things in a short amount of time..this video should be done in three or four separate videos

  • @dariopraia7424
    @dariopraia7424 5 ปีที่แล้ว

    Error: "onChange" is now deprecated, please use "onArchive", "onDelete", "onFinalize", or "onMetadataUpdate".