I'm trying to add a common function for jquery blueimp file upload in a js file, so that I can use the same function for multiple file upload inputs. I'm calling the function as:
var fileoutput = attachfile(fileobject, ['xlsx','zip'],"tmp");
This will call the function :
function attachfile(fileobject, allowedfiletypesarray, destinationfolderpath) {
var allowedFileTypes;
allowedFileTypes = allowedfiletypesarray.join('|');
allowedFileTypes = "/\.("+allowedFileTypes+")$/i";
$(fileobject).fileupload({
add: function(e, data) {
if(data.originalFiles[0]['type'].length && !allowedFileTypes.test(data.originalFiles[0]['type'])) {
$('#fileerror').html('Not an accepted file type'); // show error message
return false;
}
data.submit();
},
url: "uploadcsv.php",
dataType: 'text',
acceptFileTypes : allowedFileTypes,
formData: {"upload_url":destinationfolderpath},
done: function (e, data) {
var fileuploadresult = data.result;
fileuploadresult = JSON.parse(fileuploadresult);
console.log(fileuploadresult);
return fileuploadresult;
},
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
}
Now the issue is,
var fileoutput = attachfile(fileobject, ['xlsx','zip'],"tmp");
console.log(fileoutput);
This is returning undefined
. And I'm not getting the return from attachfile()
. console.log(fileuploadresult);
inside attachfile()
is printing the uploaded file details correctly.
Can anyone help me to solve this. Thanks in advance.