@@ -119,66 +119,95 @@ String UniversalTelegramBot::sendPostToTelegram(String command, JsonObject& payl
119
119
120
120
String UniversalTelegramBot::sendImageFromFileToTelegram (File* file, String chat_id){
121
121
122
+ Serial.println (" sendImageFromFileToTelegram" );
122
123
String response = " " ;
123
124
long now;
124
125
bool responseRecieved;
126
+ String boundry = " AaB03x" ;
125
127
// Connect with api.telegram.org
126
- if (client->connect (HOST, SSL_PORT)) {
128
+ // if (client->connect(HOST, SSL_PORT)) {
129
+ if (client->connect (HOST, SSL_PORT)) {
130
+ Serial.println (" connected" );
127
131
// POST URI
128
- client->print (" POST /bot" +_token+" /sendPhoto" ); client->println (" HTTP/1.1" );
132
+ String start_request = " " ;
133
+ String end_request = " " ;
134
+
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 " ;
140
+
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 " ;
145
+
146
+
147
+ end_request = end_request + " \n " ;
148
+ end_request = end_request + boundry + " --" + " \n " ;
149
+
150
+ // client->print("POST /bot"+_token+"/sendPhoto"); client->println(" HTTP/1.1");
151
+ client->print (" POST /post.php" ); client->println (" HTTP/1.1" );
129
152
// Host header
130
- client->print (" Host:" ); client->println (HOST);
153
+ client->print (" Host: " ); client->println (HOST);
131
154
client->println (" User-Agent: arduino/1.0" );
132
155
client->println (" Accept: */*" );
133
156
// JSON content type
134
157
// client->print("Content-Length:"); client->println(file->size() + 225);
135
158
// 175753396
136
- Serial.println (" Content-Length: " + String (file->size () + 317 + chat_id .length ()));
159
+ Serial.println (" Content-Length: " + String (file->size () + start_request. length () + end_request .length ()));
137
160
Serial.println (" File-Length: " + String (file->size ()));
138
- client->print (" Content-Length: " ); client->println (file->size () + 317 + chat_id.length ());
139
- client->println (" Expect: 100-continue" );
140
- client->println (" Content-Type: multipart/form-data, boundary=boundary=------------------------fa174948e0da42aa" );
141
- client->println (); //
142
- delay (500 );
143
- while (client->available ()) {
144
- char c = client->read ();
145
- response=response+c;
146
- }
161
+ client->print (" Content-Length: " ); client->println (file->size () + start_request.length () + end_request.length ());
147
162
148
- Serial.println (" Resp:" + response);
149
- response = " " ;
150
-
151
- client->println (" --------------------------fa174948e0da42aa" ); // 42 + 2
152
- client->println (" content-disposition: form-data; name=\" chat_id\" " ); // 48 + 2
153
- client->println (); // 2
154
- client->println (chat_id); // 2 + chat_id length
155
- client->println (" --------------------------fa174948e0da42aa" ); // 42 + 2
156
- client->println (" content-disposition: form-data; name=\" photo\" ; filename=\" img.jpg\" " ); // 64 + 2
163
+ 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(); //
157
177
158
- // client->println("Content-Type: application/octet-stream"); //38 + 2
178
+ client->print (start_request);
179
+ Serial.println (start_request);
159
180
160
- client->println (" Content-Type: image/jpeg" ); // 24 + 2
161
- client->println (" Content-Transfer-Encoding: binary" ); // 33 + 2
162
- client->println (); //
181
+ byte buff[1055 ];
182
+ int clientCount = 0 ;
163
183
164
184
165
185
Serial.println (" data" );
166
186
int count = 0 ;
167
187
char ch;
168
188
while (file->available ()) {
189
+ // buff[clientCount] = file->read();
190
+ // clientCount++;
169
191
ch = file->read ();
170
- client->print (ch);
171
- Serial.print (ch);
192
+ client->write (ch);
193
+ Serial.write (ch);
172
194
count++;
173
195
if (count > 100 ){
174
- ESP. wdtFeed ();
196
+ // yield ();
175
197
// Serial.println("feed");
176
198
count = 0 ;
177
199
}
178
200
}
179
201
180
- client->println (); // 2
181
- client->println (" --------------------------fa174948e0da42aa--" ); // 44 + 2
202
+ // if(clientCount > 0) {
203
+ // client->write(buff,clientCount);
204
+ // }
205
+
206
+ client->print (end_request);
207
+ Serial.println (end_request);
208
+
209
+ // client->println(); //2
210
+ // client->println("--------------------------fa174948e0da42aa--"); // 44 + 2
182
211
// // Content length
183
212
// //int length = payload.measureLength();
184
213
// client->print("Content-Length:"); client->println(file->size());
0 commit comments