Skip to content

ContentLength can go over 2 byte int #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

Park0
Copy link

@Park0 Park0 commented Jun 28, 2020

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 added 2 commits June 28, 2020 11:52
Converted int to long to allow for more then 65535 bytes in length
Converted int to long to allow for more then 65535 bytes in length
@salexander2
Copy link

salexander2 commented Nov 2, 2020

Hi, is necessary to adjust also the sendHeader metod:

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

@Park0
Copy link
Author

Park0 commented Nov 3, 2020

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

@salexander2
Copy link

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

@Park0
Copy link
Author

Park0 commented Nov 3, 2020

I think casting your value to int would do the trick as the method already exists:

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

@salexander2
Copy link

salexander2 commented Nov 3, 2020

I think casting your value to int would do the trick as the method already exists:

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

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.

@Park0
Copy link
Author

Park0 commented Nov 4, 2020

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

@salexander2
Copy link

salexander2 commented Nov 4, 2020

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

@admindotnu
Copy link

Any reasson why this request is not merged yet ?

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 added the topic: code Related to content of the project itself label Jan 15, 2022
@per1234 per1234 linked an issue Jan 15, 2022 that may be closed by this pull request
@andreagilardoni
Copy link

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

@andreagilardoni andreagilardoni merged commit 9d6adef into arduino-libraries:master Mar 22, 2024
1 check passed
@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ContentLength returns negative value
6 participants