Closed Park0 closed 7 months ago
Hi, is necessary to adjust also the sendHeader metod:
sendHeader(const char* aHeaderName, const int aHeaderValue);
As the const char is pointing to a real string (the value of a header in this case). I think that would be incorrect.
Hi, please check. sendHeader is an overloaded method. If you need to upload a file, and use sendHeader to set the length, the upload fails. If you adjust it, then it will work. Try please! I did it ;)
I think casting your value to int would do the trick as the method already exists: https://github.com/arduino-libraries/ArduinoHttpClient/blob/0fac9f0033de4e1f45a9e2d2a28d326c94354163/src/HttpClient.h#L198
I think casting your value to int would do the trick as the method already exists:
If you try to use this method passing a "long" value, it will not work. I tried, and I received a timeout error. After I adjusted the metod, replacing "int" with "long" it worked. Anyway, I reported it. If you release in the future a new version I know what to do to fix.
Do you have a simple example? I think i miss something.
I have my project, that is not so simple.... If you want I can show you via TeamViever. Here a piece of my code:
bool TSiteComm::upload_file(File* p_file)
{
// "multipart/form-data; boundary=RandomNerdTutorials"
// --STORNY_MY_CAR\r\n -> 17
client2.beginRequest();
client2.post("/ardu/upload.php");
client2.sendHeader("Content-Type", "multipart/form-data; boundary=STORNY_MY_CAR");
client2.sendHeader("Content-Length", 17+85+40+2+p_file->size()+2+19+2); <---------- HERE THE PROBLEM
client2.beginBody();
// --STORNY_MY_CAR\r\n -> 17
client2.println(F("--STORNY_MY_CAR"));
// Content-Disposition: form-data; name=\"dataFile\"; filename=\"20201030.txt\"\r\n -> 85
client2.print(F("Content-Disposition: form-data; name=\"dataFile\"; filename=\""));
client2.print(F(codice_veicolo));
client2.print(F("_"));
client2.print(F(p_file->name()));
client2.println("\"");
//content-type: text/plain;charset=UTF-8 -> 40
client2.println(F("content-type: text/plain;charset=UTF-8"));
// -> 2
client2.println();
while (p_file->available()) {
client2.write(p_file->read());
}
// -> 2
client2.println();
// --STORNY_MY_CAR--\r\n -> 19
client2.println(F("--STORNY_MY_CAR--"));
// -> 2
client2.println();
client2.endRequest();
Here, if I leave the parameter of sendHeader as int, the upload fails with a timeout, and errorcode -3. If I convert int to long it works.
I'm available with TeamViewer, if you want to see.
Alessandro
Any reasson why this request is not merged yet ?
Hi @Park0, thanks for your contribution, could you please sign the CLA?
When i tried to download a file over 64k i got issues on a arduinomega. This change will make the content length of type long so it will be 4 bytes.