File upload not working using knockout js. I have tried with below code but not working. Please mention where I am doing wrong.
This is my file control and button. I am
For Magento 2 below code is useful to display uploaded image by knockout js.
In html file
Js file need to code as below
define(['ko', 'uiComponent', 'jquery'], function (ko, Component, $) {
'use strict';
var photoUrl;
return Component.extend({
photoUrl : ko.observable(),
fileUpload: function(data, e)
{
var file = e.target.files[0];
var reader = new FileReader();
reader.onloadend = function (onloadend_e)
{
var result = reader.result; // Here is your base 64 encoded file. Do with it what you want.
self.photoUrl(result);
};
if(file)
{
reader.readAsDataURL(file);
}
},
});
});
}
above code is working fine with my project.