Error uploading with Idhttp android firemonkey

Asked

Viewed 171 times

0

I’m using this code to make the testing upload files to my server.

filing cabinet html where I select the file.

<html>
<body> 
<form method="post" action="upload.php" enctype="multipart/form-data">
  <label>Arquivo</label>
  <input type="file" name="userfile" />
  <input type="submit" value="Enviar" />
</form>
</body>
</html>

and the php uploader:

<?php
 $uploaddir = 'erro/';
 $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

 echo '<pre>';
 if   (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "Arquivo valido e enviado com sucesso.\n";
 }
 else {
    echo "Possivel ataque de upload de arquivo!\n";
 } 

 echo 'Aqui esta mais informacoes de debug:';
 print_r($_FILES);

 print "</pre>";
?>

is working perfectly, but when I try to send some file through the application with the code below I get an error.

procedure export_erro;
var
    params: TIdMultipartFormDataStream;
    folder,resposta: string;
begin

    try

      folder:= 'storage/emulated/0/erros/';

        if not Directoryexists(folder) then
            forcedirectories(folder);

        if FileExists(folder+'aa.txt') then
        begin

            params := TIdMultiPartFormDataStream.Create;

            params.AddFile('userfile', folder+'aa.txt', 'text/plain');

            IdHTTP1.Request.CustomHeaders.Clear;
            IdHTTP1.Request.Clear;
            IdHTTP1.Request.ContentType := 'UTF-8';
            IdHTTP1.Request.ContentEncoding := 'multipart/form-data';

            resposta:= IdHTTP1.Post('http://site.com/upload.php', params);

        end
        else
            ShowMessage('arquivo não existe!');

    except on e:exception do
        ShowMessage(e.Message);
    end;

    FreeAndNil(params);

end.

the mistake is this

HTTP/1.1 406 Not Acceptable

1 answer

0

Error 406: Not acceptable. The requested feature is only capable of generating non-acceptable content according to the Accept headers sent in the request(Link).

Problem of content type. Could be some Mime Type that the server can’t handle, invalid enconding errors, etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.