ESP32 POST JSON Base64 Attachment

Hi,

I have an Problem with POST a Base64 Picture in a JSON over the ESP32. The httpResponseCode is -1

Without attachment it works without any Problems.

After i build the JSON File in Arduino, i send it via Webocket, to test it with POSTMAN.
With Postman it works fine with this JSON (with the Attachment)

I tried this with different Pictures in different sizes/scales....

client.setCACert(PUSHOVER_ROOT_CA);
   
 if (WiFi.status() == WL_CONNECTED) 
 {


    WiFiClientSecure client;
    HTTPClient http;

    http.begin(pushoverApiEndpoint);  
    
    http.addHeader("Content-Type", "application/json"); 
    

    StaticJsonDocument<512> doc;

    doc["token"] = Token;
    doc["user"] = userToken;
    doc["title"] = "Status";
    doc["message"] = "Test";
    doc["attachment_base64"] = base64Image;
    

    String requestBody;
    serializeJson(doc, requestBody);

    webSocket.sendTXT(numbroker, requestBody);
        
    int httpResponseCode = http.POST(requestBody);

     httpResponseCodeWS = String(httpResponseCode);

     webSocket.sendTXT(numbroker, httpResponseCodeWS);
    
 
     if(httpResponseCode>0)
     {
       
      String response = http.getString();                       
       
      Serial.println(httpResponseCode);   
      Serial.println(response);
      
     
    }
    else
    {

      httpResponseCodeWS = String(httpResponseCode);
      Serial.printf("Error occurred while sending HTTP POST: %s\n");
      webSocket.sendTXT(numbroker, httpResponseCodeWS);
      
    }
    http.end();
 }
  

Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.