# Sending Image over HTTP not working

**URL:** <https://forum.amebaiot.com/t/sending-image-over-http-not-working/3226>\
**Category:** WiFi\
**Tags:** evb-amb82, rtl8735b\
**Created:** [August 9, 2024, 8:02am UTC](https://forum.amebaiot.com/t/sending-image-over-http-not-working/3226 "2024-08-09T08:02:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jash\_Doshi](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/jash_doshi/32/2209_2.png) [@Jash\_Doshi](https://forum.amebaiot.com/u/Jash_Doshi)\
**Post date:** [August 9, 2024, 8:02am UTC](https://forum.amebaiot.com/t/sending-image-over-http-not-working/3226/1 "2024-08-09T08:02:38Z")

</div>

I have hosted a server and am trying to send an image to it. It works fine in Postman; however, when trying with the amb-82 mini, these are the logs.

AP IP address: Capturing and sending image to API  
Capturing image…  
Image captured. Address: 70DE6880, Length: 83083  
[INFO] Create socket successfully  
[ERROR] start\_client Connect to server failed  
Status code: -3  
Image sending process completed  
192.168.1.1

Here is the code to it

```auto
void sendImageToAPI(uint8_t* img_addr, uint32_t img_len) {
    WiFiClient wifi;
    HttpClient client(wifi);

    String boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW";
    String contentType = "multipart/form-data; boundary=" + boundary;

    int err = client.post(api_server_ip, server_port, "/upload");
    if (err != 0) {
        Serial.print("Connect failed: ");
        Serial.println(err);
        return;
    }

client.sendHeader("Content-Type", contentType.c_str());
    unsigned long contentLength = 
        String("--" + boundary + "\r\n").length() +
        String("Content-Disposition: form-data; name=\"file\"; filename=\"image.jpg\"\r\n").length() +
        String("Content-Type: image/jpeg\r\n\r\n").length() +
        img_len +
        String("\r\n--" + boundary + "--\r\n").length();
    
    client.sendHeader("Content-Length", String(contentLength).c_str());

    client.println("--" + boundary);
    client.println("Content-Disposition: form-data; name=\"file\";filename=\"image.jpg\"");
    client.println("Content-Type: image/jpeg");
    client.println();

    // Send the image data
    client.write(img_addr, img_len);

    client.println();
    client.println("--" + boundary + "--");

    int statusCode = client.responseStatusCode();

    Serial.print("Status code: ");
    Serial.println(statusCode);
}

void captureAndSendImageToAPI() {
    Serial.println("Capturing and sending image to API");
    
    Serial.println("Capturing image...");
    Camera.getImage(CHANNEL, &img_addr, &img_len);
    Serial.print("Image captured. Address: ");
    Serial.print((unsigned long)img_addr, HEX);
    Serial.print(", Length: ");
    Serial.println(img_len);
    
    sendImageToAPI((uint8_t*)img_addr, img_len);
    Serial.println("Image sending process completed");
}

if(deviceConnected && connectedReceived){

      Serial.println("Inside connected");
        IPAddress apIP = WiFi.localIP();
        Serial.print("AP IP address: ");
        //sendImageToFlutterAppViaUDP();
        captureAndSendImageToAPI();

        Serial.println(apIP);
        delay(3000); // Wait 3 seconds        
        
        connectedReceived = false;
    }

```

Note: This thing behaved weirdly yesterday. It worked for an hour or so then it didn’t

---

<div class="post-metadata">

**Author:** ![Kelvin\_Huang](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kelvin_huang/32/2130_2.png) [@Kelvin\_Huang](https://forum.amebaiot.com/u/Kelvin_Huang)\
**Post date:** [August 12, 2024, 3:49am UTC](https://forum.amebaiot.com/t/sending-image-over-http-not-working/3226/2 "2024-08-12T03:49:58Z")

</div>

Hi @Jash_Doshi,

May I know what server are you using?

[ERROR] start\_client Connect to server failed. This shows that the communication between AMB82 mini and your server is not established. Is your server on?

I have sent post request from ameba client to nextJS app before.

Thank you.
