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

183
Visualizações
TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'

I have been struggling with this for a couple of days. I do not know why it keeps saying that my file is not a type of blob. Any help?

HTML BELOW

<form style="padding-top:10px;" method="post" action="upload.php" enctype="multipart/form-data">
                                    <input style="padding-bottom: 20px;" type="file" id="file" name="file" onchange="fileValidation(this);">
                                    <div id="responsefromfileupload" value=""></div>
                                </form>

JAVASCRIPT BELOW

function fileValidation(reader) {

var file = $("input[type=file]").get(0).files[0];
var fileInput = document.getElementById('file');
var filePath = fileInput.value;

// Allowing file type
var allowedExtensions =
    /(\.jpg|\.jpeg|\.png|\.gif)$/i;


if (!allowedExtensions.exec(filePath)) {

$("#responsefromfileupload").replaceWith(`<div style="width: 50%;" class="alert alert-danger" role="alert">
                                                    This image file type is not accepted!</div>`);
    
}

if (allowedExtensions.exec(filePath)) {

    var reader = new FileReader();

    reader.onload = function () {
        $("#previewImg").attr("src", reader.result);
        $("#previewImg").attr("margin-left", "25%");
    }

  }
  reader.readAsDataURL(file);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

function fileValidation(event) {

var file = event.target.files[0];
var fileInput = document.getElementById('file');
var filePath = fileInput.value;

// Allowing file type
var allowedExtensions =
/(\.jpg|\.jpeg|\.png|\.gif)$/i;


if (!allowedExtensions.exec(filePath)) {

$("#responsefromfileupload").replaceWith(`<div style="width: 50%;" class="alert alert-danger" role="alert">
                                                This image file type is not accepted!</div>`);

}

if (allowedExtensions.exec(filePath)) {

var reader = new FileReader();

reader.onload = function () {
    $("#previewImg").attr("src", reader.result);
    $("#previewImg").attr("margin-left", "25%");
}

  }
  reader.readAsDataURL(file);

}
<form style="padding-top:10px;" method="post" action="upload.php" enctype="multipart/form-data">
                                <input style="padding-bottom: 20px;" type="file" id="file" name="file" onchange="fileValidation(event);">
                                <div id="responsefromfileupload" value=""></div>
                            </form>

The template you can use - remove space between < and !--

< !-- begin snippet: js hide: false console: true babel: false -->

< !-- language: lang-js -->

< !-- language: lang-html -->

< !-- language: lang-css -->

< !-- end snippet -->

about 4 years ago · Juan Pablo Isaza Relatório
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