How to Upload a File to Google Cloud Storage in Node.js

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

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

  • @ephraim-duncan
    @ephraim-duncan 3 ปีที่แล้ว +1

    I miss these Ben Awad days

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

    Thank you so much for this video! With your help I fixed a bug in my bucket access. Yeah!

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

    Thanks man, you save my day!

  • @ВадимАлекс-щ6ъ
    @ВадимАлекс-щ6ъ ปีที่แล้ว

    Thanks for the lesson!

  • @MichaelZodok
    @MichaelZodok 3 ปีที่แล้ว +1

    This is why I hate cloud storage!! You have to practically be an IT specialist to access your files.

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

    Thank you very much, work as a charm!

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

    Hey, great topic. Thank you

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

    Nice, next time I'll ask you soon, about gcp :D Thx Ben

  • @AbhishekKumar-mq1tt
    @AbhishekKumar-mq1tt 5 ปีที่แล้ว +2

    Thank u for this awesome video

  • @true2urself
    @true2urself 7 หลายเดือนก่อน

    Great! What if there's a need to create a NojeJS API to interact with the bucket?

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

    S3 supports browser direct uploads. It would be nice to have a similar tutorial on google storage

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

      www.google.com/amp/s/cloudblog.withgoogle.com/products/storage-data-transfer/uploading-images-directly-to-cloud-storage-by-using-signed-url/amp/

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

      wow that looks way more involved than S3's

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

    so much thanks! this really help me

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

    Works great. But how to upload multiple files or even an entire folder to GCP??

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

    Hi Dear...i can read the file but if i try to upload one, i get a weird error...not related with your code:
    Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Failed to read the 'signal' property from 'RequestInit': Failed to convert value to 'AbortSignal'.

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

    lol 5 min ago I was searching for a tutorial on this.

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

      yes, and?

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

      @@iJuce yes and?

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

      @@blasttrash ok.. and?

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

      @@iJuce so?

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

    *Problem is mentioned in almost middle of the Comment* . *This is written there* -> " *I am having problem here.. this assignment is not working* "
    var mysql = require('mysql');
    var express = require('express');
    var app = express();
    var con = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "hennastore"
    });
    con.connect(function (err) {
    if (err) {
    throw err;
    }
    else {
    console.log("Connected!")
    };
    })
    app.get('/hennaread', function (request, response) {
    // function photos(id) {
    // return con.query("SELECT img_path FROM images WHERE store_id =" + id)
    // .then(imagesPath => {
    // return imagesPath
    // }).catch(err => console.log(err))
    // }
    // function photos(id) {
    // con.query("SELECT * FROM images WHERE store_id =" + id, function (error, resultss) {
    // if (error) {
    // return Array();
    // }
    // else {
    // // callback(resultss);
    // return resultss.json();
    // // return id;
    // // response.send(resultss)
    // }
    // });
    // }
    con.query('select * from store', function (error, results) {
    if (error) {
    response.status(400).send('Error in database operation');
    } else {
    // rest = { data };
    var i = 0;
    var arr1 = [];
    var arr_2 = [];
    data1 = new Object();
    var api = [];
    var arr3 = [];
    for (i = 0; i < results.length; i++) {
    // var resultsss = {}
    con.query('select img_path from images WHERE store_id =' + results[i].store_id, function (error, resultss) {
    if (error) {
    response.status(400).send('Error in database operation');
    }
    else {
    ********I am having problem here.. this assignment is not working********
    ********I am having problem here.. this assignment is not working********
    ********I am having problem here.. this assignment is not working********
    arr3 = [resultss];
    }
    })
    // var photo = ;
    // console.log(photo);
    c_data = {
    "store_id": results[i].store_id
    , "store_category": results[i].categery_id
    , "store_name": results[i].store_name
    , "store_owner": results[i].store_owner,
    "store_image": results[i].store_image,
    "store_detail": results[i].store_detail,
    "store_image": results[i].store_image,
    "store_discounts": results[i].store_discounts,
    "store_promotions": results[i].store_promotions,
    "store_phone1": results[i].store_phone1,
    "store_phone2": results[i].store_phone2,
    "store_rating": results[i].store_rating,
    "store_phone1": results[i].store_phone1,
    "store_longitude": results[i].store_longitude,
    "store_latitude": results[i].store_latitude,
    "store_address": results[i].store_address,
    "store_link": results[i].store_link,
    "store_facebook_link": results[i].store_facebook_link,
    // "photos": photos(results[i].store_id)
    // .then((resultss) => {
    // console.log(resultss)
    //do stuff here on success
    // })
    // .catch(err => {
    // // handle errors here if any
    // }),
    "photos": arr3,
    "store_timings": ["Monday " + results[i].Monday_open + " - " + results[i].Monday_close,
    "Tuesday " + results[i].Tuesday_open + " - " + results[i].Tuesday_close,
    "wednesday " + results[i].Wednesday_open + " - " + results[i].Wednesday_close,
    "Thursday " + results[i].Thursday_open + " - " + results[i].Thursday_close,
    "Friday " + results[i].Friday_open + " - " + results[i].Friday_close,
    "Saturday " + results[i].Saturday_open + " - " + results[i].Saturday_close,
    "Sunday " + results[i].Sunday_open + " - " + results[i].Sunday_close
    ]
    };
    arr_2.push(c_data);
    }
    data1.other = arr_2;
    rest1 = { data1 }
    response.send(
    rest1
    )
    }
    }
    )
    })
    app.listen(3000, function () {
    console.log('Express server is listening on port 3000');
    })

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

      your using a callback and that doesn't stop the function from executing

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

      @@bawad what should i do then ?

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

      Try using a promise

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

    const {createReadStream, filename} = await file
    createReadStream is not function.. how to solve?

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

    any suggestions on updating the query so that it will display the uploaded images?

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

    Thanks for the amazing video but Can you please tell how to show the file in UI , if bucket is private?

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

    Hey Ben I have a question, I have integrated cloud storage for upload and download but for upload what I'm doing is I use multer with in memory storage, how do I optimise it for high loads because my server may run out of memory on spikes. File size can be atmost 100mb

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

      use signed urls to upload directly to cloud storage

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

    it says cannot read property join of undefined in the keyFilename join

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

    I'm new to using GCS and would please like to know how to retrieve a file after I've uploaded it. Thanks

  • @mariaflorenciacaballero9669
    @mariaflorenciacaballero9669 3 ปีที่แล้ว +1

    Hi! thanks for the video! I could upload the image from my node.js server to de google cloud api and then mi react component gets the right url (if i put in the browser that url it shows the image) but still the img html tag goes to the alt and i dont know why.. Anyone could help me??

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

      Hello! Also faced with this. Have you found a solution?

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

    Can you show an example of a download from Storage using node js with express?

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

      Whenever I code that sure

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

    I would love to know what that json file looks like. Any idea anyone? I have a key but it seems I can't just pass it as a string.

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

      i'm sorry is an old question, but i find out is same key firebase create. you can check on here console.cloud.google.com/

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

    Hi, can u make a series about sequalize, sql and node js?

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

      have you watched my slack clone? th-cam.com/video/0MKJ7JbVnFc/w-d-xo.html

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

    Hi Ben, did you ever implemented saving files to a google drive in node js for users who has to give permission? If you did, do you have any tips? What api did you use? Trying to figure it out.😃

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

      haven't yet

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

      @@bawad Nice challenge 😁

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

    Great video! I have the exact same setup, and everything works, except the uploaded image is broken when I view it in the google console. Do you have any ideas on why? :(

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

      Use an alternative with apps script, example th-cam.com/video/m3Sc7nVLPP8/w-d-xo.html

  • @nini-ic7is
    @nini-ic7is 4 ปีที่แล้ว +2

    wait I need credit card info to create an account? wtf

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

    Is there any risk for having images public for a site that needs to upload a lot of images - for example a bucket to hold thousands of product images.
    It doesn't matter if these images are public in this example (in the sense that it's ok if someone views them all), but if someone was to cycle through all the images constantly (possibly maliciously), your bill would essentially be unlimited.
    Is there some way to make images private, but accessible by the front end/your backend etc?

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

      probably, but I haven't look into it much

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

    if create a blog like app using MERN can I use this method to upload images like post, and can other user post as well..... ?🤔

  • @isaquemoura9991
    @isaquemoura9991 3 ปีที่แล้ว +1

    thanks from brazil o/

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

    Im getting this 500 error : invalid grant invalid jwt: Token must be a short-lived version (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim. Does anyone have any idea on how to solve this?

    • @00000sander
      @00000sander 3 ปีที่แล้ว

      This is probably not relevant for you anymore, but for any future readers when regenerating a new jwt token you must remove the iat and exp properties from the authenticated user details you're passing on to the jwt.sign.

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

    Very nice video, liked a lot. Question: can I use google cloud storage client library in a google cloud function, or I want to know if it is incorrect?? Wich is the best way to do it?

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

      I'm not sure, I haven't tried cloud functions

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

      @@bawad thanks, I'll check it out.

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

    me sirvio! gracias!

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

    Hi Ben, may you make a video about google cloud for databases, like implementing a redis or postgres instance

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

      where are you running into trouble?

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

      @@bawad both, but instead postgres I use MySQL :p

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

      when you create a db on google cloud it should give you a url you can use

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

    thanks!!

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

    Have you tried digitalocean spaces? 5$ for 250gb storage and 2tb traffic

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

      I haven't, the price is enticing but I heard the speed was meh

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

    If you provide a path to a JSON file, the projectId is not necessary.

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

      cool, thanks

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

    Were you not using S3 Transfer Acceleration?

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

      nope

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

    Hi Ben, can you also teach how the graphql mutation to delete the image from google server.

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

      Do you know how to delete an image from google using their API?

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

    thanks

  • @8siaix
    @8siaix 3 ปีที่แล้ว

    how to set expiration for the file

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

    thanks a lot

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

    how to upload react js image to google bucket???

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

    allUsers access gives an error anymore

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

    i still dont understand from where the apollo test json file came ??

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

      google cloud credentials, you'll get them from google

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

      @@bawad aa, thanks ! keep it uup

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

    Is there a solution to use env variable instead of json file

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

      copy the file content needed to env file and use dotenv

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

    Plot Twist: He only made the video to show the front-end framework tierlist on his desktop (8:28)

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

    Can I provide the bucket URL to put files in it thru nodejs ?

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

      I'm not sure

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

      @@bawad I have to provide the Path as a param among others in JSON format for third party app, how can I put the location of the bucket so that this third party can put the file on it (I can only provide the location where to put the file, I don't have control on this third party) Thanks.

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

    how much data, we can store for free?

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

      you get a $300 credit when you sign up

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

      @@bawad every month or once?, And how much google charge per GB?

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

    just fuckin perfect god bless you :)

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

      happy to help :)

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

    There is one way that i can upload files from url? Example:
    storage.bucket(firebaseConfig.storageBucket)
    .upload('www.my-site.com/myImage.jpg', {
    gzip: true,
    metadata: {
    cacheControl: 'public, max-age=31536000',
    },
    });

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

    very hard to understand

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

      Just rewrite the code or request th-cam.com/video/m3Sc7nVLPP8/w-d-xo.html

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

    Excellent video, thank you!