Trouble Streaming File From Secure Server
Posted: Thu May 10, 2018 5:03 pm
I have a file on a HTTPS server. I can get the URL I send into DownloadMenuFile() [<see below] and put it into a browser or into Postman and get the file but when I use my code below, the GET returns 200, the file size is correct and the stream pointer is valid but the stream size is 0. What is going on?
The URLs are one use because of the token and look like this, names changed to protect the guilty...
https://someplace.cloud/app/upload/devi ... 927e32dcb8
The URL above is passed into the function below.
The Fingerprint is valid. If I change it the connection is not established.
// Genuno Settings
// Board: NodeMCU 1.0 (ESP-12E Module)
// ESP8266Libraries -> ESP8266-2.4.0
// Flash Mode: DIO
// Flash Freq: 40MHz
// CPU Freq: 80MHz
// Flash Size: 4M(3M SPIFFS)
// Reset Method: ck
// Upload Speed: 115200
// Programmer: AVRISP mkii
Thanks in advance...
The URLs are one use because of the token and look like this, names changed to protect the guilty...
https://someplace.cloud/app/upload/devi ... 927e32dcb8
The URL above is passed into the function below.
The Fingerprint is valid. If I change it the connection is not established.
// Genuno Settings
// Board: NodeMCU 1.0 (ESP-12E Module)
// ESP8266Libraries -> ESP8266-2.4.0
// Flash Mode: DIO
// Flash Freq: 40MHz
// CPU Freq: 80MHz
// Flash Size: 4M(3M SPIFFS)
// Reset Method: ck
// Upload Speed: 115200
// Programmer: AVRISP mkii
Code: Select all
void DownloadMenuFile(char downUrl[])
{
HTTPClient httpClient;
char buf[130] = {0};
uint8_t bufferD[128] = {0};
int httpCode = 0;
// We now create a URI for the request
DEBUG_PRINT(downUrl);
httpClient.begin(downUrl, "73 3A E4 C2 BA 9F B8 FC D9 BD 6D 1C 64 7F FA 6B B8 48 F4 08");
testStack(); // Plenty of stack
httpClient.setReuse(true);
httpCode = httpClient.GET();
Serial.println(httpCode); // I get 200
if (httpCode >0)
{
DEBUG_PRINT("downloadFile Connected");
int len = httpClient.getSize();
Serial.print("File size: ");
sprintf(buf, "%d", len); // The length is valid
Serial.println(buf);
WiFiClient* myStream = httpClient.getStreamPtr();
if(myStream ) // This is always valid
{
while (httpClient.connected() && (len > 0 || len == -1))
{
// get available data size
size_t sizeStream = myStream->available();
Serial.print("Stream Size:");
sprintf(buf,"%d",sizeStream);
Serial.println(buf); // THIS IS ALWAYS 0
if (sizeStream) // I NEVER GET IN HERE
{
// read up to buffer size
int c = myStream->readBytes(bufferD, ((sizeStream > sizeof(bufferD)) ? sizeof(bufferD) : sizeStream));
sprintf(buf, "Data: %s", bufferD);
Serial.println(buf);
Serial.print("bytes read:");
Serial.println(c);
if (len > 0)
{
len -= c;
}
}
else
len = -2;
delay(1);
}
}
}
else
{
DEBUG_PRINT("ERROR: downloading file from cloud.");
handleHTTPError(httpCode);
}
httpClient.end(); //Close connection
DEBUG_PRINT("Complete");
return ;
}
Thanks in advance...