Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipar/form-data + CT_MULTIPART_FORM_DATA #2226

Open
the3wave opened this issue Dec 7, 2024 · 0 comments
Open

multipar/form-data + CT_MULTIPART_FORM_DATA #2226

the3wave opened this issue Dec 7, 2024 · 0 comments

Comments

@the3wave
Copy link

the3wave commented Dec 7, 2024

when compiling the project and I do MAKE:

20241207 22:51:21.317064 UTC 1045052 DEBUG [submit] Headers recebidos: - loginControll.cc:34
20241207 22:51:21.317144 UTC 1045052 DEBUG [submit] accept-language: ru,en;q=0.9,pt;q=0.8 - loginControll.cc:37
20241207 22:51:21.317154 UTC 1045052 DEBUG [submit] sec-fetch-user: ?1 - loginControll.cc:37
20241207 22:51:21.317162 UTC 1045052 DEBUG [submit] host: localhost - loginControll.cc:37
20241207 22:51:21.317167 UTC 1045052 DEBUG [submit] connection: keep-alive - loginControll.cc:37
20241207 22:51:21.317172 UTC 1045052 DEBUG [submit] origin: http://localhost - loginControll.cc:37
20241207 22:51:21.317176 UTC 1045052 DEBUG [submit] referer: http://localhost/loginControll/newuser - loginControll.cc:37
20241207 22:51:21.317180 UTC 1045052 DEBUG [submit] content-length: 726 - loginControll.cc:37
20241207 22:51:21.317184 UTC 1045052 DEBUG [submit] sec-fetch-mode: navigate - loginControll.cc:37
20241207 22:51:21.317189 UTC 1045052 DEBUG [submit] sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "YaBrowser";v="24.10", "Yowser";v="2.5" - loginControll.cc:37
20241207 22:51:21.317193 UTC 1045052 DEBUG [submit] sec-fetch-dest: document - loginControll.cc:37
20241207 22:51:21.317197 UTC 1045052 DEBUG [submit] sec-ch-ua-mobile: ?0 - loginControll.cc:37
20241207 22:51:21.317201 UTC 1045052 DEBUG [submit] sec-fetch-site: same-origin - loginControll.cc:37
20241207 22:51:21.317205 UTC 1045052 DEBUG [submit] user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 YaBrowser/24.10.0.0 Safari/537.36 - loginControll.cc:37
20241207 22:51:21.317210 UTC 1045052 DEBUG [submit] cache-control: max-age=0 - loginControll.cc:37
20241207 22:51:21.317217 UTC 1045052 DEBUG [submit] upgrade-insecure-requests: 1 - loginControll.cc:37
20241207 22:51:21.317221 UTC 1045052 DEBUG [submit] sec-ch-ua-platform: "Linux" - loginControll.cc:37
20241207 22:51:21.317238 UTC 1045052 DEBUG [submit] content-type: application/x-www-form-urlencoded - loginControll.cc:37
20241207 22:51:21.317241 UTC 1045052 DEBUG [submit] accept-encoding: gzip, deflate, br, zstd - loginControll.cc:37
20241207 22:51:21.317247 UTC 1045052 DEBUG [submit] accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7 - loginControll.cc:37
20241207 19:51:21.317009 POST /loginControll/submit [726] (127.0.0.1:59992 - 127.0.0.1:80) 400 Bad Request 176 0.000263

The client sent multipart/form-data but the server receives: content-type: application/x-www-form-urlencoded - loginControll.cc:37

c++ code:
try {
// Verificar o tipo de conteúdo
auto oque=req->contentType();

std::string oque2="
















FORM não é CT_MULTIPART_FORM_DATA


";

LOG_DEBUG << "Headers recebidos:";
for (const auto &header : req->getHeaders())
{
LOG_DEBUG << header.first << ": " << header.second;
}

    if (req->contentType() != drogon::CT_MULTIPART_FORM_DATA)
    {
        auto response = HttpResponse::newHttpResponse();
        response->setStatusCode(k400BadRequest);
        response->setBody(oque2);
        callback(response);
        return;
    }
    

    // Processar arquivos enviados
    MultiPartParser fileParser;
    fileParser.parse(req);
    
  // Check if have files
  if (fileParser.getFiles().empty()) {
LOG_ERROR << "Nenhum arquivo enviado.";
callback(HttpResponse::newHttpResponse());
return;
  }        

    // Iterar pelos arquivos enviados
    std::vector<std::string> caminho;
    
    size_t num_of_files = fileParser.getFiles().size();
    
    
    for (const auto &file : fileParser.getFiles())
    {
    
        
       std::string filename              = file.getFileName(); // ok
       size_t      filesize              = file.fileLength();
       auto        file_extension        = file.getFileExtension();            
       file.save("../../../uploads/meubras/"+filename); // Writes the file in the indicated directory, with the original name

        
        caminho.push_back("../../../uploads/meubras/"+filename);


        // Salvar o arquivo no diretório de uploads
      /*   std::ifstream src(tempPath, std::ios::binary);
           std::ofstream dst(savePath, std::ios::binary);
           dst << src.rdbuf();
      */
      
    }

Operating System:
Linux localhost.localdomain 5.14.0-503.14.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 19 21:25:22 EST 2024 x86_64 x86_64 x86_64 GNU/Linux

drogon version:
A utility for drogon
Version: 1.9.8
Git commit: 1765223
Compilation:
Compiler: c++
Compiler ID: GNU
Compilation flags: -O3 -DNDEBUG -std=c++17 -I/usr/include -I/usr/local/include
Libraries:
postgresql: no (pipeline mode: no)
mariadb: no
sqlite3: yes
ssl/tls backend: OpenSSL
brotli: no
hiredis: no
c-ares: yes
yaml-cpp: no

even though I put a <form action="/loginControll/submit"" method="POST" enctype="multipart/form-data" hx-encoding="multipart/form-data">, the server receives a content-type: application/x-www-form-urlencoded - loginControll.cc:37.

what's going on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant