ArduinoHttpClient icon indicating copy to clipboard operation
ArduinoHttpClient copied to clipboard

ContentLength can go over 2 byte int

Open Park0 opened this issue 5 years ago • 9 comments

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.

Park0 avatar Jun 28 '20 10:06 Park0

Hi, is necessary to adjust also the sendHeader metod:

sendHeader(const char* aHeaderName, const int aHeaderValue);

salexander2 avatar Nov 02 '20 08:11 salexander2

As the const char is pointing to a real string (the value of a header in this case). I think that would be incorrect.

Park0 avatar Nov 03 '20 19:11 Park0

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 ;)

salexander2 avatar Nov 03 '20 19:11 salexander2

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

Park0 avatar Nov 03 '20 19:11 Park0

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

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.

salexander2 avatar Nov 03 '20 20:11 salexander2

Do you have a simple example? I think i miss something.

Park0 avatar Nov 04 '20 19:11 Park0

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

salexander2 avatar Nov 04 '20 19:11 salexander2

Any reasson why this request is not merged yet ?

admindotnu avatar Jan 18 '21 09:01 admindotnu

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 09 '21 13:04 CLAassistant

Hi @Park0, thanks for your contribution, could you please sign the CLA?

andreagilardoni avatar Mar 21 '24 16:03 andreagilardoni