Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
Javascript Filereader pdf upload with image

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!