arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
282 stars 170 forks source link

ArduinoHttpClient with Headers for sending file #145

Closed asadi2021 closed 1 year ago

asadi2021 commented 1 year ago

Hi, I tried to send an image from ESP32CAM to web by ArduinoHttpClient.h and SIM800L . But it does not work . I used post with headers by changing the following code :

const char server[] = "Mysite.com";
const char resource[] = "/Mysystem/getdata_test.php";
String head = "--NEWSystem\r\nContent-Disposition: form-data; name=\"imageFile\"; filename=\"esp32-cam.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n";
String tail = "\r\n--NEWSystem--\r\n";

uint32_t imageLen = img_len;  //fb->len;
uint32_t extraLen = head.length() + tail.length();
uint32_t totalLen = imageLen + extraLen;
http.beginRequest();
http.post(uploadPath);
http.sendHeader("Content-Type: multipart/form-data; boundary=NEWSystem");
http.sendHeader("Content-Length: " + String(totalLen));
http.sendHeader(head);
http.beginBody();
uint8_t *fbBuf = fb->buf;
size_t fbLen = fb->len;
for (size_t n = 0; n < fbLen; n = n + 1024) {
  if (n + 1024 < fbLen) {
    http.write(fbBuf, 1024);
    fbBuf += 1024;
  } else if (fbLen % 1024 > 0) {
    size_t remainder = fbLen % 1024;
    http.write(fbBuf, remainder);
  }
}
http.print(tail);

http.endRequest();
* / int status = http.responseStatusCode();
SerialMon.print(F("Response status code: "));
SerialMon.println(status);

This is result:

Go to send photo .....
Read from file: Connecting to server: Mysite.com
Response status code: -3
Response: 
per1234 commented 1 year ago

Hi @asadi2021. Thanks for your interest in this open source project. This issue tracker is only to be used to report bugs or feature requests specific to the project. This topic is more appropriate for the Arduino Forum. I'm sure we will be able to help you out over there:

https://forum.arduino.cc/