@@ -123,131 +123,76 @@ String UniversalTelegramBot::sendImageFromFileToTelegram(File* file, String chat
123
123
String response = " " ;
124
124
long now;
125
125
bool responseRecieved;
126
- String boundry = " AaB03x " ;
126
+ String boundry = " ------------------------b8f610217e83e29b " ;
127
127
// Connect with api.telegram.org
128
- // if (client->connect(HOST, SSL_PORT)) {
129
128
if (client->connect (HOST, SSL_PORT)) {
130
129
Serial.println (" connected" );
131
130
// POST URI
132
131
String start_request = " " ;
133
132
String end_request = " " ;
134
133
135
- start_request = start_request + " \n " ;
136
- start_request = start_request + " --------------------------fa174948e0da42aa" + " \n " ;
137
- start_request = start_request + " content-disposition: form-data; name=\" chat_id\" " + " \n " ;
138
- start_request = start_request + " \n " ;
139
- start_request = start_request + chat_id + " \n " ;
134
+ start_request = start_request + " --" + boundry + " \r\n " ;
135
+ start_request = start_request + " content-disposition: form-data; name=\" chat_id\" " + " \r\n " ;
136
+ start_request = start_request + " \r\n " ;
137
+ start_request = start_request + chat_id + " \r\n " ;
140
138
141
- start_request = start_request + boundry + " \n " ;
142
- start_request = start_request + " content-disposition: form-data; name=\" photo\" ; filename=\" img.jpg\" " + " \n " ;
143
- start_request = start_request + " Content-Type: image/jpeg" + " \n " ;
144
- start_request = start_request + " \n " ;
139
+ start_request = start_request + " -- " + boundry + " \r \n" ;
140
+ start_request = start_request + " content-disposition: form-data; name=\" photo\" ; filename=\" img.jpg\" " + " \r\ n " ;
141
+ start_request = start_request + " Content-Type: image/jpeg" + " \r\ n " ;
142
+ start_request = start_request + " \r\ n " ;
145
143
146
144
147
- end_request = end_request + " \n " ;
148
- end_request = end_request + boundry + " --" + " \n " ;
145
+ end_request = end_request + " \r\ n " ;
146
+ end_request = end_request + " -- " + boundry + " --" + " \r \n" ;
149
147
150
- // client->print("POST /bot"+_token+"/sendPhoto"); client->println(" HTTP/1.1");
151
- client->print (" POST /post.php" ); client->println (" HTTP/1.1" );
148
+ client->print (" POST /bot" +_token+" /sendPhoto" ); client->println (" HTTP/1.1" );
152
149
// Host header
153
150
client->print (" Host: " ); client->println (HOST);
154
151
client->println (" User-Agent: arduino/1.0" );
155
152
client->println (" Accept: */*" );
156
- // JSON content type
157
- // client->print("Content-Length:"); client->println(file->size() + 225);
158
- // 175753396
159
- Serial.println (" Content-Length: " + String (file->size () + start_request.length () + end_request.length ()));
160
- Serial.println (" File-Length: " + String (file->size ()));
161
- client->print (" Content-Length: " ); client->println (file->size () + start_request.length () + end_request.length ());
162
153
154
+ int contentLength = file->size () + start_request.length () + end_request.length ();
155
+ Serial.println (" Content-Length: " + String (contentLength));
156
+ client->print (" Content-Length: " ); client->println (String (contentLength));
163
157
client->println (" Content-Type: multipart/form-data; boundary=" + boundry);
164
- //
165
- // client->println("--------------------------fa174948e0da42aa"); //42 + 2
166
- // client->println("content-disposition: form-data; name=\"chat_id\""); //48 + 2
167
- // client->println(); //2
168
- // client->println(chat_id); //2 + chat_id length
169
- // client->println("--------------------------fa174948e0da42aa"); //42 + 2
170
- // client->println("content-disposition: form-data; name=\"photo\"; filename=\"box.jpg\""); //64 + 2
171
- //
172
- // //client->println("Content-Type: application/octet-stream"); //38 + 2
173
- //
174
- // client->println("Content-Type: image/jpeg"); //24 + 2
175
- // //client->println("Content-Transfer-Encoding: binary"); //33 + 2
176
- // client->println(); //
158
+ client->println (" " );
177
159
178
160
client->print (start_request);
179
- Serial.println (start_request);
180
-
181
- byte buff[1055 ];
182
- int clientCount = 0 ;
183
-
161
+ Serial.print (start_request);
184
162
185
- Serial.println (" data" );
163
+ Serial.println (" Sending...." );
164
+ char buffer[512 ];
186
165
int count = 0 ;
187
166
char ch;
188
167
while (file->available ()) {
189
- // buff[clientCount] = file->read();
190
- // clientCount++;
191
- ch = file->read ();
192
- client->write (ch);
193
- Serial.write (ch);
168
+ buffer[count] = file->read ();
169
+ // client->write(ch);
170
+ // Serial.write(ch);
194
171
count++;
195
- if (count > 100 ){
172
+ if (count == 512 ){
196
173
// yield();
197
- // Serial.println("feed");
174
+ Serial.println (" Sending full buffer" );
175
+ client->write ((const uint8_t *)buffer, 512 );
198
176
count = 0 ;
199
177
}
200
178
}
201
179
202
- // if(clientCount > 0) {
203
- // client->write(buff,clientCount);
204
- // }
180
+ if (count > 0 ) {
181
+ Serial.println (" Sending remaining buffer" );
182
+ client->write ((const uint8_t *)buffer, count);
183
+ }
205
184
206
185
client->print (end_request);
207
- Serial.println (end_request);
208
-
209
- // client->println(); //2
210
- // client->println("--------------------------fa174948e0da42aa--"); // 44 + 2
211
- // // Content length
212
- // //int length = payload.measureLength();
213
- // client->print("Content-Length:"); client->println(file->size());
214
- // Serial.println(file->size());
215
- // // End of headers
216
- // client->println();
217
- //
218
- // Serial.println("data");
219
- // int count = 0;
220
- // char ch;
221
- // while (file->available()) {
222
- // ch = file->read();
223
- // client->println(ch);
224
- // //Serial.println(ch);
225
- // count++;
226
- // if(count > 50){
227
- // ESP.wdtFeed();
228
- // Serial.println("feed");
229
- // count = 0;
230
- // }
231
- // }
232
-
233
- Serial.println (" Done" );
234
- Serial.println (" Done" );
235
- Serial.println (" Done" );
236
- Serial.println (" Done" );
186
+ Serial.print (end_request);
237
187
238
188
189
+ Serial.println (" Done" );
239
190
count = 0 ;
240
191
int ch_count=0 ;
241
192
char c;
242
193
now=millis ();
243
194
responseRecieved=false ;
244
195
while (millis ()-now<1500 ) {
245
- // if(count > 100){
246
- // ESP.wdtFeed();
247
- // Serial.println("feed1");
248
- // count = 0;
249
- // }
250
- // count++;
251
196
while (client->available ()) {
252
197
char c = client->read ();
253
198
// Serial.write(c);
0 commit comments