I am having an issue with my file upload from javascript to laravel and displaying it for later use, below is my code to upload and save to db and retrieve later and display it
$(document).on("change", "#facesheet", function() {
handleFileSelect($(this));
});
function handleFileSelect(evt) {
var files = $(evt)[0].files; // FileList object
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var fileString = e.target.result;
$("#divFileUpload").removeData("file");
$("#divFileUpload").removeData(
"filename");
$("#divFileUpload").removeData("extension");
$("#divFileUpload").data("file", fileString);
$("#divFileUpload").data(
"filename", theFile.name);
$("#divFileUpload").data("extension", theFile
.name.split('.').pop().toLowerCase());
};
})(f);
reader.readAsDataURL(f);
}
}
on submit button in modal, this code will execute and saves to db using base64_encode object and stores as blob
function uploadpdf() {
var $formdata = {
'data': $("#divFileUpload").data("file"),
'filename': $("#divFileUpload").data("filename"),
'type': $("#divFileUpload").data("extension"),
'Number': $("#hdnNumber").val()
};
$.ajax({
url: '/upload',
type: 'POST',
data: $formdata,
success: function(response) {
alert("Uploaded successfully");
window.location.reload();
}
});
return false;
}
when a user click on the uploaded file it opens a new window to display the file. Everything works fine with this as long as pdf contains text data but when pdf is completely an image then it wont display anything, any help will be appreciated on this.