1

Atm I'm saving simple strings in local storage. But the problem is now I want to save videos/images to local storage. But since localStorage only supports strings I don't see how this would be possible.

If you could provide with code example that would be good!

<form #userForm = "ngForm" (ngSubmit)="onSubmit(userForm.value)">
<div class="form-group">
        <label for="exampleInputFile">File input</label>
        <input type="file" class="form-control-file" id="image" aria-describedby="fileHelp" accept="image/*, video/*" ng name="image" ngModel>
        <small id="fileHelp" class="form-text text-muted"></small>
    </div>    
</form>

add-profile.components.ts

 onSubmit(value: any){
    localStorage.setItem(this.getId(), JSON.stringify(value));
  }
Amar
  • 509
  • 2
  • 15
  • 36
  • 1
    The real question would be: why are you doing this? You can store a handful of MBs (https://stackoverflow.com/questions/2989284/what-is-the-max-size-of-localstorage-values) in local storage. If you want to save binary data as a string, you encode the data, for example in base64. But still not a good idea. – CodeCaster Sep 25 '17 at 11:08
  • I'm doing this as a temporary solution because I'm not supposed to use server/database at this point. I will move the local storage implementation to the server/database later on. – Amar Sep 25 '17 at 11:11
  • Here is a solution which saves and retrieves any file in localstorage: https://stackoverflow.com/a/55090255/5935112 – Just Shadow Mar 10 '19 at 17:16

1 Answers1

0

https://github.com/ninjatronic/angular-base64

Use something like this to convert the image to base64 as CodeCaster said. But it's a bad idea, and you may run out of space and it won't work anyways. If I remember correctly (double check) but it's 10mb per localstorage so a video won't save there (tiny low quality video maybe).

Why don't you use a local db temporarily?

Mark
  • 217
  • 4
  • 15
  • But either way I must convert to base64? That is if I use local db or local storage – Amar Sep 25 '17 at 12:25