2

How do I store the image that will be uploaded to the input type file into a variable to then be previewed into the DOM? I'm using a MEAN stack if this helps with an answer.

            <form method="post">
                <label class="app-file-input button" flow-init>
                    <span>Upload</span>
                    <i class="icon-enter"></i>
                    <input type="file" flow-btn/>
                    <img flow-img="$flow.files[0]" />
                </label>
            </form>

I've read once the image has been uploaded it gets stored in a temp storage. How would I access that to then preview the image before uploading?

Cheers

MaxwellLynn
  • 613
  • 5
  • 19
  • 40

2 Answers2

1

You need to do it the Angular way... If you are trying to implement your own solution you can use this simple code: https://stackoverflow.com/a/31952876/407245

However if I were you, I would use something like this https://github.com/danialfarid/ng-file-upload or https://github.com/nervgh/angular-file-upload

Community
  • 1
  • 1
Chris Cinelli
  • 4,103
  • 3
  • 25
  • 38
0

This is whats i got for you :

Please take a look at the sample JS code below:

function readURL(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}



 $(document ).on('change','#imgInp' , function(){ readURL(this); });

and the associated HTML:

<form id="form1" runat="server">
    <input type='file' id="imgInp" />
    <img id="blah" src="#" alt="your image" />
</form>

See DEMO

Referal

Community
  • 1
  • 1
Amar Singh
  • 4,757
  • 2
  • 21
  • 45