0

I have successfully stored a base64 image to the local storage.

I have tried and failed in adding the stored value to an input file field.

document.getElementsByName("inputfieldname")[0].setAttribute("value", getSavedValue("thesavedkey"));

<input type="file" name="inputfieldname">
Lhen
  • 181
  • 3
  • 15

2 Answers2

2

you can't set a value in this way to a file type input due to legacy security vulnerabilities.

Hank X
  • 1,988
  • 2
  • 14
  • 32
  • There seems to be a solution here. Just can't seem to get my head over it. https://stackoverflow.com/questions/19183180/how-to-save-an-image-to-localstorage-and-display-it-on-the-next-page – Lhen Dec 13 '18 at 10:09
  • @badboy this is just parsing the image into base64 format and then saving to localStorage, and then showing it somewhere, like input field (type=text). however, what you wanted is to set the value of a `type=file` input, which is impossible. but if you want to send the base64 data to your server and then create image from it on your server, it is possible. – Hank X Oct 26 '21 at 14:27
1
document.getElementById('mytext').value =  = window.sessionStorage.getItem('user')

try above one.

PPShein
  • 13,309
  • 42
  • 142
  • 227