Created
March 9, 2020 11:23
-
-
Save jovanialferez/89d5d91985b5b52a582ae8205dee3efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #js-profile-pic-upload --> <input id='js-profile-pic-upload' type=file /> | |
$('#js-profile-pic-upload').on('change', function () { | |
const supplierId = $(this).data('supplierId'); | |
var form = new FormData(); | |
form.append('photo', $(this)[0].files[0]); | |
$.ajax({ | |
type: 'POST', | |
url: `/upload-photo`, | |
data: form, | |
cache: false, | |
contentType: false, | |
processData: false, | |
success: resp => $('#js-profile-pic').attr('src', resp.url), | |
error: err => console.error(err) | |
}); | |
// preview while uploading above is in progress | |
var reader = new FileReader(); | |
reader.onload = (e) => { | |
// That image dom element to show the "preview" | |
$('#js-profile-pic').attr('src', e.target.result); | |
} | |
reader.readAsDataURL($(this)[0].files[0]); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment