Repository navigation
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
I send a photo to telegram via SIM800 and TinyGSM. If the photo is more than 16384b I get an error "bad request: image_process_failed".
Are there any restrictions on the size of the transferred files and how to correctly transfer large files more than 16 KB using the SSLCLIENT library
I am using ESP32-CAM Gsm module sim800l Arduino IDE V2.0.
#define TINY_GSM_MODEM_SIM800
#define CAMERA_MODEL_AI_THINKER
#include <WiFi.h>
#include <TinyGsmClient.h>
#include <TinyGsmClientSIM800.h>
#include <ArduinoHttpClient.h>
#include <SSLClientESP32.h>
#include <camera.h>
#include <FastBot2.h>
#include <ArduinoJson.h>
#include <Arduino.h>
#define BOTtoken "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
TinyGsm modem(Serial2);
TinyGsmClient client(modem);
SSLClientESP32 telegramSSL(&client);
FastBot2Client bot(telegramSSL);
const char apn[] = ""; //apn
const char user[] = ""; //username
const char pass[] = ""; //pass
void setup()
{
telegramSSL.setCACert(cert);
Serial.begin(115200);
bool res = cam_init(FRAMESIZE_QQVGA, PIXFORMAT_JPEG);
Serial.println(res ? "Camera OK" : "Camera ERROR");
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
Serial.print(F("Waiting for network..."));
if (!modem.waitForNetwork()) {
Serial.println(" fail");
return;
}
Serial.println(" OK");
Serial.print(F("Connecting to "));
Serial.print(apn);
if (!modem.gprsConnect(apn, user, pass)) {
Serial.println(" fail");
return;
} else {
Serial.println(" OK");
}
IPAddress local = modem.localIP();
modem.waitResponse();
Serial.println(local);
bot.setToken(F(BOTtoken));
bot.setPollMode(fb::Poll::Long, 20000);
}
void loop() //put function inside loop if required
{
String chat_id = "123456789";
String text = "hello!";
Serial.println("Send message");
bot.sendMessage(fb::Message("Hello!", chat_id));
delay(1000);
camera_fb_t* fbj = esp_camera_fb_get();
esp_camera_fb_return(fbj);
fbj = esp_camera_fb_get();
if (fbj) {
fb::File f("frame.jpg", fb::File::Type::photo, fbj->buf, fbj->len);
f.chatID = chat_id;
bot.sendFile(f, true);
}
esp_camera_fb_return(fbj);
}
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed
Activity
RobertByrnes commentedon May 23, 2025
You are encountering the "bad request: image_process_failed" error when sending images >16KB to Telegram via SIM800 and TinyGSM. This is a common issue due to several factors—let’s break down the probable causes and solutions.
1. Telegram Bot API File Size Limits
2. SIM800L Module and TinyGSM/SSLClient Limits
3. Why <16KB Works, But Larger Fails
4. Solution: Chunked/Buffered Uploads
You must send the file in small chunks, not all at once!
Here’s how to do it robustly:
How to Send Large Files with SSLClient/TinyGSM
A. Use Streaming/Chunked API
If your HTTP client supports it, use the
beginBody()/write()/endRequest()APIs (or similar) to send the file incrementally.B. Manually Chunk the Buffer
If working with a raw HTTP POST/PUT or multipart upload, send the file in 1-2KB chunks:
C. For Libraries Like FastBot2
write()method of your client (telegramSSL).D. HTTP Multipart:
5. Power Supply Issues
6. Recommendations for Your Code
sendFile()if it’s >2-4KB.client.write()call for the full buffer, it will fail for big files.Summary Table
Actionable Steps
telegramSSL.write()in a loop.References
RobertByrnes commentedon Nov 1, 2026
A correction to my earlier reply: there is not enough evidence here to conclude that SIM800L has a 16 KB total file-transfer limit, or that passing a complete buffer to sendFile() must fail. The previous sample loop was also incorrect because it ignored write()'s return value and advanced by the requested length, which can silently skip unsent data.
The exact 16,384-byte boundary is worth investigating as a TLS fragment/partial-write boundary, rather than assuming it is a whole-file limit. mbedTLS can write fewer bytes than requested, particularly above the outgoing fragment size; its caller must retry the remaining bytes with the advanced pointer. This repository's SSLClient::write() currently returns the count from send_ssl_data(), which returns the first positive mbedtls_ssl_write() result. An upload layer that assumes that result always equals the requested size could therefore truncate a larger upload. This is a plausible mechanism, not yet a confirmed diagnosis of your setup.
The posted sketch uses SSLClientESP32.h and SSLClientESP32, whereas this repository exposes SSLClient.h and SSLClient. Please provide the exact repository/version of the SSL implementation actually used, plus FastBot2, its HTTP transport dependency, TinyGSM, and ESP32 core versions. If you tested both SSL implementations, please distinguish the results. I also found the matching upstream report at GyverLibs/FastBot2#37; these investigations can be cross-referenced without assuming that either library is responsible.
To narrow this down:
For clarity, Telegram currently documents a 10 MB multipart photo-upload limit, not the 20 MB photo limit stated in my previous reply. It is far above the reported boundary: https://core.telegram.org/bots/api#sendphoto
mbedTLS partial-write contract: https://mbed-tls.readthedocs.io/projects/api/en/v2.28.10/api/file/ssl_8h/#c.mbedtls_ssl_write
Please retest this repository's implementation on 1.3.3 if applicable, but the 1.3.3 idle-read fix is not a confirmed fix for this upload issue. Keeping this open with help wanted pending the library/version and write-count results.