Uploading files to HTTP server

Anton_Dru
Posts: 7
Joined: Sun Dec 27, 2020 7:01 pm

Uploading files to HTTP server

Postby Anton_Dru » Mon Nov 01, 2021 2:04 pm

Hi!
There is a task to upload images and audio to the HTTP server. I need to do this using AT commands on ESP32-C3. For this I use the AT command AT + HTTPCPOST https://docs.espressif.com/projects/es ... -httpcpost

As it turns out, simply using the AT + HTTPCPOST command is not enough to upload files to the server. To do this, a specific header must be sent along with the command. The developers of the server to which the data needs to be sent have provided the required header type:

POST /http_path HTTP/1.1
Host: example.com
Content-Type: multipart/form-data;
Content-Disposition: form-data; name = "image"; filename = "example.jpg"
Content-Type: image/jpeg


The string POST/http_path HTTP/1.1 is generated by ESP32 based on the URL entered in the main part of the command. The rest of the lines are <http_req_header> (optional part of the AT command). Thus, a fully formed AT command for sending data to the server looks like this:

Code: Select all

AT+HTTPCPOST="http://example.com/http_path",57118,4,"Host: example.com","Content-Type: multipart/form-data","Content-Disposition: form-data; name=image; filename=1.jpg "," Content-Type: image/jpeg "
As you can see from the command, the file size is 57118 bytes.

After receiving a positive response:

Code: Select all

OK

>
I am transferring files.
After transferring the file, a message about successful transfer is received:

Code: Select all

SEND OK
In this case, the server replies that the files could not be loaded.

According to the server administrators, the POST request occurs, but the files are not loaded.

For a more complete understanding of what is transmitted to the server, I created on the local computer using the HFS program http://www.rejetto.com/hfs/ and captured the data using Wireshark. The following URL is used http://192.168.x.xxx/test_folder/ When trying to download files using the above AT command, files also do not appear, but the server writes that a POST request has occurred. At the same time, Wireshark shows the following structure of the HTTP packet:

Hypertext Transfer Protocol
POST /test_folder/HTTP/1.1\r\n
User-Agent: ESP32 HTTP Client/1.0\r\n
Host: 192.168.x.xxx\r\n
Content-Type: image/jpeg\r\n
Content-Disposition: form-data; name = image; filename = 1.jpg\r\n
Content-Length: 57118\r\n
\r\n
[Full request URI: http://192.168.x.xxx/test_folder/]
[HTTP request 1/2]
[Response in frame: 1228]
File Data: 57118 bytes


From this I can judge that the HTTP header is formed in accordance with the requirements of the server developers, but the files are not loaded.

Tell me, maybe I'm making some mistake that I don't notice?
Does anyone have really working examples of uploading files to the HTTP server using the ESP32 AT commands?

Who is online

Users browsing this forum: No registered users and 76 guests