I\'m trying to upload a file (as of now of any extension) in extjs. I have a model and store. the file upload happens from a window and I dont have a form in the window. All
If you want to still use ExtJS's fileuploadfield and upload through an AJAX call using HTML5 FileReader, you can do it like such:
launchUpload: function () {
//get a handle of the "file" input in the widget itself...
var fileInput = document.getElementById(yourUploadField.button.fileInputEl.id);
var fileReader = New FileReader();
var fileToUpload = fileInput.files[0]; //assuming your only uploading one file...
var me = this
fileReader.onload = function (e) {
me.onLoadFile(e, me, fileToUpload.name);
}
fileReader.readAsDataURL(fileToUpload);
},
onLoadFile: function (e, scope, filename) {
//I carry the scope around for functionality...
Ext.Ajax.request({
method: 'POST',
url: 'url',
scope: scope,
jsonData: { fileNameParameter: filename, fileDatainBase64: e.target.result},
success: function (response, operation) {
//success..
},
failure: function (response, operation) {
//failure...
}
});
}