1

I am using ng2fileupload to upload the pic to the server the code is working the fine and the image is getting uploaded but I want to show the image before sending it to the server for uploading my code is given below

  <img src="" >

  <input type="file" placeholder="Upload file"  ng2FileSelect [uploader]="uploader">
  <button class="btn btn-success btn-s" role="submit" (click)="uploader.uploadAll()" [disabled]="passwordForm.valid">
      Update 
  </button>

I am not able to get the path of the image so I am not able to send it to src of img tag. Any help is appreciated.

Abhishek Singh
  • 900
  • 7
  • 19
  • 1
    Maybe, you can handle the upload of image by yourself in a method of your component. Doing so, I guess it will be easier to get the path of the image before sending it. Here is a [link](https://stackoverflow.com/questions/40214772/file-upload-in-angular-2?rq=1), where you can see how to upload a file. – edkeveked Oct 20 '17 at 20:04

1 Answers1

1

Here is a link to an article that shows you how to do just what you want to do. It just doesn't use Angular to do it. https://scotch.io/tutorials/use-the-html5-file-api-to-work-with-files-locally-in-the-browser.

Basically, you need to use the file api to convert the file into a data URL, and set the "src" to that url.

theGleep
  • 1,179
  • 8
  • 14