Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda