1

I'm trying to post the buffer generated by the ESP32 camera to my personal API service I have built with Node.JS. The post gets sent successfully. I have yet to test it on large image (higher resolution).

I'm using a FRAMESIZE_HQVGA, // 240x176 for my images

void postImage(uint8_t* buf, size_t len)
{
  // prepare JSON document
  DynamicJsonDocument doc(len);
  doc["buffer"] = buf;

HTTPClient http;

// Serialize JSON document String json; serializeJson(doc, json);

http.begin("http://192.168.0.147:3001/api/pictures"); http.addHeader("Content-Type", "application/json");

int httpResponseCode = http.POST(json);

if (httpResponseCode > 0) { // response String response = http.getString(); Serial.println(httpResponseCode); Serial.println(response); } else { Serial.print("Error sending POST: "); Serial.println(httpResponseCode); }

// disconnect http.end(); }

In my Node.JSside, I receive the buffer but I'm unable to de serialize it to an image. This i smy body:

{ buffer: '����' }

I'm wondering what I'm doing wrong here. Should the image buffer be sent in base64, and if so, how? I want to be able to transform the image buffer into a proper image on the API side.

Here's my how I try to transform the image buffer to a proper image (in my API controller):

    const imageBuffer = Buffer.from(req.body.buffer);
    const filename = `./resources/pictures/image_${Date.now()}.jpg`;
fs.writeFile(filename, imageBuffer,function(err) {
    if (err) {
        console.log(err);
    } else {
        console.log(`Writing ${filename}`);
    }
}); 

Johnny boy
  • 121
  • 2

0 Answers0