user39683: My application runs on an ESP32-CAM.
It takes pictures and stores to SPIFFS.
Periodically SPIFFS is checked and if images are found:
1- The image is saved to a FTP server
2- The image is summited to a Web Service that returns some informations about the image
3- Values are saved to mySQL
4- The image is deleted from SPIFFS
To read the image from SPIFFS I use the following fragment of code:
String imageName   = file.name();  
imageBuffer = "";
while (file.available()){
   imageBuffer += char(file.read());
}

The FTP transfer works perfectly with the following command:
ftp.WriteData((uint8_t*)imageBuffer.c_str(),imageBuffer.length());

The service the image is submited for analizes works OK if I use the command:
webClient.write(fb->buf,fb->len);

But as it is not usable in the current implementation of my project I am trying to work with:
webClient.write((uint8_t*) imageBuffer.c_str(), imageBuffer.length());

I get no errors in return but it just does not work and the web service at the destination returns nothing.
What Am I doing wrong?

user4143: You should not use String to store binary data.
Instead allocate yourself an array of uint8_t of the right size.
uint8_t *imageData;
size_t len = file.size();

imageData = alloca(len);
file.readBytes(imageData, len);

webClient.write(imageData, len);

With that said, without knowing what the rest of your program is doing I can only surmise that you're just blasting raw data at the web server and hoping it sticks. That's not how web data transfers work. You have to craft the upload page properly as multi-part mime form data. Read this for more information

user39683: OK, I got it to work as follows:
Not passing the binary anymore, passing the file name so the FTPPost function will do its own reading of the file on SPIFFS and will post in 256 bytes chunks.
The same strategy works with HTTP post to the WebService.
  File picFile = SPIFFS.open(fileName,FILE_READ);
  const size_t bufferSize = 256;
  uint8_t buffer[bufferSize];
  while (picFile.available()) {
    size_t n = picFile.readBytes((char*) buffer, bufferSize);
    if (n != 0) {
      ftp.WriteData(buffer, n);
    } else {
      Serial.println(F("Buffer was empty"));
      break;
    }
  }
  picFile.close();


39683: <p>My application runs on an ESP32-CAM.
It takes pictures and stores to SPIFFS.
Periodically SPIFFS is checked and if images are found:
1- The image is saved to a FTP server
2- The image is summited to a Web Service that returns some informations about the image
3- Values are saved to mySQL
4- The image is deleted from SPIFFS</p>
<p>To read the image from SPIFFS I use the following fragment of code:</p>
<pre><code>String imageName   = file.name();  
imageBuffer = &quot;&quot;;
while (file.available()){
   imageBuffer += char(file.read());
}
</code></pre>
<p>The FTP transfer works perfectly with the following command:</p>
<pre><code>ftp.WriteData((uint8_t*)imageBuffer.c_str(),imageBuffer.length());
</code></pre>
<p>The service the image is submited for analizes works OK if I use the command:</p>
<pre><code>webClient.write(fb-&gt;buf,fb-&gt;len);
</code></pre>
<p>But as it is not usable in the current implementation of my project I am trying to work with:</p>
<pre><code>webClient.write((uint8_t*) imageBuffer.c_str(), imageBuffer.length());
</code></pre>
<p>I get no errors in return but it just does not work and the web service at the destination returns nothing.</p>
<p>What Am I doing wrong?</p>
 4143: <p>You should not use <code>String</code> to store binary data.</p>
<p>Instead allocate yourself an array of <code>uint8_t</code> of the right size.</p>
<pre class="lang-cpp prettyprint-override"><code>uint8_t *imageData;
size_t len = file.size();

imageData = alloca(len);
file.readBytes(imageData, len);

webClient.write(imageData, len);
</code></pre>
<p>With that said, without knowing what the rest of your program is doing I can only surmise that you're just blasting raw data at the web server and hoping it sticks. That's not how web data transfers work. You have to craft the upload page properly as multi-part mime form data. <a href="https://stackoverflow.com/questions/8659808/how-does-http-file-upload-work">Read this for more information</a></p>
 39683: <p>OK, I got it to work as follows:</p>
<p>Not passing the binary anymore, passing the file name so the FTPPost function will do its own reading of the file on SPIFFS and will post in 256 bytes chunks.
The same strategy works with HTTP post to the WebService.</p>
<pre><code>  File picFile = SPIFFS.open(fileName,FILE_READ);
  const size_t bufferSize = 256;
  uint8_t buffer[bufferSize];
  while (picFile.available()) {
    size_t n = picFile.readBytes((char*) buffer, bufferSize);
    if (n != 0) {
      ftp.WriteData(buffer, n);
    } else {
      Serial.println(F(&quot;Buffer was empty&quot;));
      break;
    }
  }
  picFile.close();
</code></pre>
