drogonframework / drogonframework/drogon

multipar/form-data + CT_MULTIPART_FORM_DATA

Open
#2,226 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
14.3k
Forks
1.4k
Avg merge
1d 13h
Merged PRs (30d)
14

Description

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 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: 1765223755ebb54891fab644ed622bb6e2adeffc
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 , the server receives a content-type: application/x-www-form-urlencoded - loginControll.cc:37.

what's going on?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.