How to Save Images to Local/Session Storage - JavaScript Tutorial

Поделиться
HTML-код
  • Опубликовано: 19 июл 2020
  • In today's video I'll be showing you how to save images to Local or Session Storage using JavaScript. This is easily achieved using the FileReader and data URLs.
    Support me on Patreon:
    / dcode - with enough funding I plan to develop a website of some sort with a new developer experience!
    For your reference, check this out:
    developer.mozilla.org/en-US/d...
    developer.mozilla.org/en-US/d...
    Follow me on Twitter @dcodeyt!
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #javascript #webdev

Комментарии • 90

  • @dcode-software
    @dcode-software  4 года назад +20

    PLEASE NOTE: There are size limitations to Local Storage - as of Jul 2020 it appears to be around 5MB per origin. With this in mind, try to only save smaller sized images where necessary and if you need to save larger images, use a link instead :)

    • @CodeZhifty
      @CodeZhifty 3 года назад

      I have this music player where i need to save my mp3 files to sessionstorage how do i work around this size limit? And does it even work with mp3 files?

    • @varunthecoder2389
      @varunthecoder2389 3 года назад

      sir use live server extension for refreshing

    • @janekiii
      @janekiii 2 года назад

      what do u mean by use a link? :)

    • @NiketBahety
      @NiketBahety 2 года назад +1

      @@janekiii It means that you can temporarily upload them somewhere and use that link like some cloud storage or someplace like that

    • @janekiii
      @janekiii 2 года назад

      @@NiketBahety thanks for the explanation :)

  • @derda4402
    @derda4402 Год назад +3

    I needed a way for users to upload one image to set it as their background and this works perfectly. I have just recently learned web dev so I haven't gotten to cloud storage, API, etc yet and I love how this easily fixed my problem

  • @chellovlogs
    @chellovlogs 3 года назад +2

    Thank you! That was exactly what I was searching for, and I couldn`t expect better explanation!

  • @joeydikgole6005
    @joeydikgole6005 Год назад +1

    Awesome tutorial. I'm loving this channel everyday. Thank you

  • @NiketBahety
    @NiketBahety 2 года назад +1

    Amazing tutorial very clear and precise and exactly what I was looking for. Thank you !!

  • @louleg23
    @louleg23 3 года назад

    Very clear and helpful - just what I was looking for. Thanks.

  • @anikkhan8811
    @anikkhan8811 3 года назад +1

    Eyy Mate! This is exactly what was I looking for! Many many thanks!

  • @raymondmichael4987
    @raymondmichael4987 4 года назад

    That is real great brother,
    Greetings from Tanzania 🇹🇿

  • @israeluribe2010
    @israeluribe2010 3 года назад +2

    Amazing! Helped me a lot. Thanks!

  • @awaismadni8811
    @awaismadni8811 9 месяцев назад +1

    Thanks bro, it was pretty awesome, simple and quite straight-forward 💞

  • @smurffronda2951
    @smurffronda2951 3 года назад

    thank you man, have a great week

  • @nicopostigo123
    @nicopostigo123 2 года назад +1

    Great tutorial, thanks!

  • @christopherkuhn6117
    @christopherkuhn6117 3 года назад

    Thanks, helped me a lot!

  • @s.w.swestern_gem3913
    @s.w.swestern_gem3913 3 года назад

    Thank you for saving my life I owe you 3000

  • @marimobaka95
    @marimobaka95 2 года назад

    omg u saved my mental health thank u so much

  • @juliocsfarias
    @juliocsfarias 2 года назад

    Thank you guy!

  • @luisffernandezlopez3552
    @luisffernandezlopez3552 2 года назад

    Thank you very much bro

  • @gopalloharnew5948
    @gopalloharnew5948 2 года назад

    It's amazing !

  • @taher786...
    @taher786... 2 года назад +1

    a very straight forward video, thanks a ton man

  • @anmolsingh6567
    @anmolsingh6567 4 месяца назад

    Useful 🌟❣️❣️❣️❣️

  • @nikhilpatil8798
    @nikhilpatil8798 4 года назад

    bro ur like a god

  • @alihoseynzadeh7267
    @alihoseynzadeh7267 2 года назад

    verry helpful

  • @rizzz_one_4343
    @rizzz_one_4343 2 года назад

    wow!!! thanks for it..

  • @noone-gr4is
    @noone-gr4is 3 года назад

    this code is nicely organized/organised!

  • @user-kf1di5uw9i
    @user-kf1di5uw9i 2 года назад

    Great! Thanks a lot

  • @noone-gr4is
    @noone-gr4is 3 года назад

    +1 subscriber!

  • @hmedh3476
    @hmedh3476 3 года назад

    Thank u

  • @reynaldoramos9564
    @reynaldoramos9564 2 года назад +1

    This there a way to have the image show on innerHTML for example if I can using this code to generate an image for a book list application? TIA

  • @balenata9359
    @balenata9359 4 года назад +1

    please what theme you use this color really nice and also your explination really nice

  • @guilhermealexander4855
    @guilhermealexander4855 2 года назад

    my like, Thank you!

  • @maheshmorem5665
    @maheshmorem5665 2 года назад

    Perfect

  • @jagadeeshkumar2091
    @jagadeeshkumar2091 3 года назад

    Thanks you!

  • @reactteamwdp7648
    @reactteamwdp7648 2 года назад

    thank you so much sir

  • @MsDEAD27End
    @MsDEAD27End 4 года назад +1

    Bro, this information is gold. thanks, by the way, how much space i have for save photos or for example, another files like pdf , word, excel etc

    • @dcode-software
      @dcode-software  4 года назад +1

      A lot of this is about balance - remember you'd be saving it against the user's machine so if you can, try and save only what's required 😁

  • @bangunny
    @bangunny 3 года назад

    this method will do the same with multi images right ?

  • @atakan7901
    @atakan7901 Год назад

    Thats perfect video thank you .I want to ask a question.
    why picture opens only while we refresh it? Doesnt it open when we press to open button ? Is this possible ?

  • @thathojohannes1862
    @thathojohannes1862 Год назад +2

    How do I retrieve the image(using javascript) so that it can be displayed on another page?

  • @KantiOke
    @KantiOke 3 года назад

    How to make it no refresh? One select file it will auto load? And once the main index is open the image will auto load. How to do it?

  • @noone-gr4is
    @noone-gr4is 3 года назад

    which font do u use?

  • @PrilaRis
    @PrilaRis 2 года назад

    how do i download bulk images in twitter with coding in chrome developer tools?

  • @yazeedmohamadalqahtani1814
    @yazeedmohamadalqahtani1814 4 года назад

    Please make video about how to auto play video in javascript

  • @rodrigocabotajejr6214
    @rodrigocabotajejr6214 2 года назад +1

    So the image didn't save in the local folder instead, it become 64based image?

  • @abd11868
    @abd11868 3 года назад

    great tutorial... can we send this data-url as json to server?

  • @pantherking6857
    @pantherking6857 3 года назад

    does this work with videos?

  • @WindowsVista80
    @WindowsVista80 3 года назад

    how do i make it so that all the pictures stay on the page

  • @kishorgopal7113
    @kishorgopal7113 Год назад

    i am getting unexpected error when using query selector... please help to resolve that

  • @samyyoussef8380
    @samyyoussef8380 2 года назад

    helpful, but remeber in the upfront of ur video u said you will type 3,4 line codes, ended to be dilemma

  • @TamilLatest
    @TamilLatest 2 года назад

    How do I do it with video?

  • @lightcode6487
    @lightcode6487 3 года назад

    So will the images still exist on the page when you leave and go to it again? ANd nice video

    • @dcode-software
      @dcode-software  3 года назад +1

      Yes they will

    • @lightcode6487
      @lightcode6487 3 года назад

      @@dcode-software Woooow nice that was exactly what I was looking for: Display a selected image in input and save it thank you very much also for this very quick answer. Left a sub too :)

    • @dcode-software
      @dcode-software  3 года назад +1

      Appreciate that mate, cheers 🙂

    • @lightcode6487
      @lightcode6487 3 года назад

      @@dcode-software One more question: Is it possible to put multiple inputs and put in and save individual images in each of them? Like I've got a first input I put an image in and then I add a second input and put in another image?

    • @JoseFuentes-vm9ql
      @JoseFuentes-vm9ql 2 года назад

      @@lightcode6487 i have the same question

  • @sherifsalah5563
    @sherifsalah5563 4 года назад

    What is the size limit for all browsers?
    I just checked (again) coz i tried to do this before but found out its not that usable in real world because of local storage limit on browsers is from 2 to 10 MBs which is extremely small for image's storage.

    • @dlol.
      @dlol. 4 года назад

      You could store a link to the image, saving you a ton of space

    • @dcode-software
      @dcode-software  4 года назад

      Storing a link to the image is definitely a good alternative in the case of larger files

    • @ademineshat
      @ademineshat 3 года назад

      @@dcode-software can you please give me a hint about storing link? I've tried but i can just get the filename not the link?

    • @lepystudio8974
      @lepystudio8974 2 года назад

      @@ademineshat just add a input with the type=url and save it as string ... localstorage.setItem(url.value);

  • @codefoxx
    @codefoxx 3 года назад

    fuck yea! I was looking for drag and drop but this is also good !

  • @abdelrahmanmohamed4990
    @abdelrahmanmohamed4990 8 месяцев назад

    What if I want to make it appear just by clicking the choose btn?
    How can I achieve that plz?
    I love your channel by the way🤝❤️

  • @forheuristiclifeksh7836
    @forheuristiclifeksh7836 Год назад

    3:02 how to treat many files not a single file?

  • @el4710
    @el4710 3 года назад

    what folder the image save after uploaded?

    • @princejones0077
      @princejones0077 2 года назад

      It isn't uploaded. it's saved in the browser's local storage as a database key thus converting it to base64 string first.

  • @search3923
    @search3923 Год назад +2

    Only one file can upload and save 🙄,not multiple images can ..

  • @muhammadimadkhan7978
    @muhammadimadkhan7978 3 года назад

    How can save image in local storage in an angular can any one help me

  • @Selva982
    @Selva982 2 года назад

    How to take snaps via print screen and store in word automatically

  • @mehraj43
    @mehraj43 2 года назад +1

    plzz tell your theme name

  • @codergirl5092
    @codergirl5092 3 года назад

    I need when someone choose a file then the image should be saved in my project folder...if anyone knows how to do kindly reply

    • @joebrock3496
      @joebrock3496 3 года назад

      you would need php for that, i suppose

  • @sosad7832
    @sosad7832 2 года назад

    I have an error it says "this.files is undefined"

  • @user-yd7db3wd7w
    @user-yd7db3wd7w 4 года назад

    That's all call but why would one store images in local storage? Isn't it inefficient?

    • @lukaskovar6921
      @lukaskovar6921 4 года назад

      BASE64 encoding takes about 26% more space than binary. It's not that bad.

    • @user-yd7db3wd7w
      @user-yd7db3wd7w 4 года назад

      @@lukaskovar6921 I thought it's not about space but about time and resources it requires

  • @kittentothecode
    @kittentothecode 2 года назад

    @change="(e)=>console.log(e.target.files)" with Alpine.js