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

169
Visualizações
File not sending with FormData in Ajax request

I have an ajax request that is sending a file along with some other info. Everything except the file is the correct value, and the file is always null. I can't figure out why.

Here is the input I have included in the form:

<input type="file" id="file" runat="server"/>

On button click, it calls this function:

function ButtonClick() {
    var file = document.getElementById('file').files[0]; // correctly gets the file

    var formData = new FormData();
    formData.append('key1', 'val1');
    formData.append('key2', 'val2');
    formData.append('file', file, file.name);

    $.ajax({
        cache: false,
        data: formData,
        dataType: 'json',
        processData: false,
        contentType: false,
        success: function (data, textStatus, jqXHR) { closeWindow(); },
        timeout: 30000,
        type: 'POST',
        url: '<%= ResolveClientUrl("~/api/Example/ExampleUrl") %>'
    });
}

When I receive the request server-side, I get the following values:

var key1= HttpContext.Current.Request.Form["key1"]); // returns "val1"
var key2= HttpContext.Current.Request.Form["key2"]); // returns "val2"
var file= HttpContext.Current.Request.Form["file"]); // returns "null"

And when I take a look at HttpContext.Current.Request.Form, "file" is not in the request at all.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The file should be accessible via

HttpContext.Current.Request.Files["file"]
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