Upload high resolution images using ESP32 cam

I am using ESP 32 - CAM for uploading images. When i upload the image pixels are missing in it. Ideally, FRAMESIZE_UXGA(1600x1200) image size should be around 100Kb but I am recieving just 50 Kb,

I am guessing its a problem related to buffer.

#include "FS.h"
#include "SD_MMC.h"
#include <Wire.h>
#include <WiFi.h>
#include <Adafruit_Sensor.h>
#include "src/Adafruit_TSL2591/Adafruit_TSL2591.h"
#include "src/esp32-camera/esp_camera.h"

bool isCapture = false;
int minThreashold = 100;
/*
    Two thresholds can be set:

    Lower Threshold - Any light sample on CHAN0 below this value
                      will trigger an interrupt
    Upper Threshold - Any light sample on CHAN0 above this value
                      will trigger an interrupt
*/
// Interrupt thresholds and persistance
#define TLS2591_INT_THRESHOLD_LOWER  (1)
#define TLS2591_INT_THRESHOLD_UPPER  (100)
#define TLS2591_INT_PERSIST        (TSL2591_PERSIST_ANY) // Fire on any valid change
//#define TLS2591_INT_PERSIST          (TSL2591_PERSIST_60)  // Require at least 60 samples to fire

void setup(void)
{

   Serial.begin(115200);
    if(!SD_MMC.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
    uint8_t cardType = SD_MMC.cardType();

    if(cardType == CARD_NONE){
        Serial.println("No SD_MMC card attached");
        return;
    }

      uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
    Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
  
   Serial.printf("SPIRam Total heap %d, SPIRam Free Heap %d\n",ESP.getPsramSize(),ESP.getFreePsram());
}

void loop(void)
{
  captureImage();
   fileUpload();
  }


}

camera_fb_t * fb = NULL;
size_t size_pic;
int counter = -1;
uint8_t* myImages;

void captureImage() {
  Serial.println("Camera capture started");

  int64_t fr_start = esp_timer_get_time();
  int index = ++counter % 2;
  Serial.println("Capture index:");
  Serial.print( counter);
  myImages=(uint8_t*) ps_malloc(100000*sizeof(uint8_t));
  fb = esp_camera_fb_get();
  myImages = fb->buf;
  size_pic = fb->len;
  if (!fb) {
    Serial.println("Camera capture failed");
  }
}

void fileUpload() {
  Serial.println("inside file upload");
  if (counter > -1) { 

    Serial.println("Captured images : ");
    Serial.print(counter);
    sendImage("asdw", "A54S89EF5");
   
  }
}
String sendImage(String token, String message)
{

  Serial.println("inside send image");
  int index = --counter % 2;
  String bodyTxt =  body("message", message);
  String bodyPic =  body("imageFile", message);
  String bodyEnd =  String("--") + BOUNDARY + String("--\r\n");
  size_t allLen = bodyTxt.length() + bodyPic.length() + fb->len + bodyEnd.length();
  String headerTxt =  header(token, allLen);
  WiFiClient client;
  if (!client.connect(SERVER, PORT))
  {
    return ("connection failed");
  }

  client.print(headerTxt + bodyTxt + bodyPic);
  client.write(myImages, fb->len);
  client.print("\r\n" + bodyEnd);

  delay(5000);
  long tOut = millis() + TIMEOUT;
  while (client.connected() && tOut > millis())
  {
    if (client.available())
    {
      String serverRes = client.readStringUntil('\r');
      return (serverRes);
    }
  }
  free(myImages);
    counter = -1;
}
String header(String token, size_t length)
{
  String  data;
  data =  F("POST /camera/saveCameraData/1/5c9e7ab9e9ee5102a406dd1f HTTP/1.1\r\n");
  data += F("cache-control: no-cache\r\n");
  data += F("Content-Type: multipart/form-data; boundary=");
  data += BOUNDARY;
  data += "\r\n";
  data += F("User-Agent: PostmanRuntime/6.4.1\r\n");
  data += F("Accept: */*\r\n");
  data += F("Host: ");
  data += SERVER;
  data += F("\r\n");
  data += F("accept-encoding: gzip, deflate\r\n");
  data += F("Connection: keep-alive\r\n");
  data += F("content-length: ");
  data += String(length);
  data += "\r\n";
  data += "\r\n";
  return (data);
}
String body(String content , String message)
{
  String data;
  data = "--";
  data += BOUNDARY;
  data += F("\r\n");
  if (content == "imageFile")
  {
    data += F("Content-Disposition: form-data; name=\"image\"; filename=\"picture.jpg\"\r\n");
    data += F("Content-Type: image/jpeg\r\n");
    data += F("\r\n");
  }
  else
  {
    data += "Content-Disposition: form-data; name=\"" + content + "\"\r\n";
    data += "\r\n";
    data += message;
    data += "\r\n";
  }
  return (data);
}

Thanks in advance for your help.

First, you need to use code tags to post your code. Read the first four posts on this Forum for the proper use of code tags. Second, you should always post all of your code, not just a fragment. You may think your problem is in a specific section of code, but it's not uncommon to find the problem in another section of code.

@econjack Thanks for letting me know

  myImages=(uint8_t*) ps_malloc(100000*sizeof(uint8_t));
  fb = esp_camera_fb_get();
  myImages = fb->buf;

This does not make sense. First, you allocate 100000 bytes of memory, and make myImages point at the allocated space. Then, you abandon that space, without freeing the memory, by making myImages point somewhere else.

Where is fb defined? How?

  free(myImages);

Then, you free some other memory that you didn't allocated, f*cking up the fb object...

  client.print("\r\n" + bodyEnd);

  delay(5000);
  long tOut = millis() + TIMEOUT;
  while (client.connected() && tOut > millis())

There is no valid reason for that useless delay().

Ideally, FRAMESIZE_UXGA(1600x1200) image size should be around 100Kb

If there is one byte per pixel, then that is 1920000 bytes. Do you really have room in memory for two copies of that image data?

but I am recieving just 50 Kb,

The first 50Kb? The last 50Kb? Some random set from the almost 200Kb image that you have duplicated in memory?

@PaulS I know I did something wrong with memory allocation.

All I need to do is, use SPRAM to save my captured image and then upload it using Wificlient.

camera_fb_t * fb = NULL;

hi @abhi1005
did you get your code working?
If yes please let me know because i am also getting the same problem..
Thanks in advance!!