Firebase Storage Inconsistent Download Sizes #537
-
Hey all, Another question. I'm using v4.3.19 with ESP8266 (SPIFFS filesystem as per example) and getting inconsistent download sizes. I'm downloading a ~680kb file, and using the download example if i check the file size after download, i get a different value each time (it's not consistent). Actual File Size : 685,200 Size on SPIFFS : Also tried reverting to older versions and still seems to be an issue Is anyone else seeing anything similar? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You should check your file properly. The library works well on filesystem and I can confirm that there is no issue like that. |
Beta Was this translation helpful? Give feedback.
-
Test with this example code using this file. #include <Arduino.h>
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>
// Provide the token generation process info.
#include <addons/TokenHelper.h>
// Provide the SD card interfaces setting and mounting
#include <addons/SDHelper.h>
/* 1. Define the WiFi credentials */
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"
/* 2. Define the API Key */
#define API_KEY "API_KEY"
/* 3. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "USER_EMAIL"
#define USER_PASSWORD "USER_PASSWORD"
/* 4. Define the Firebase storage bucket ID e.g bucket-name.appspot.com */
#define STORAGE_BUCKET_ID "BUCKET-NAME.appspot.com"
// Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long ms = 0;
int count = 0;
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
WiFiMulti multi;
#endif
void setup()
{
Serial.begin(115200);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
multi.addAP(WIFI_SSID, WIFI_PASSWORD);
multi.run();
#else
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#endif
Serial.print("Connecting to Wi-Fi");
unsigned long ms = millis();
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
if (millis() - ms > 10000)
break;
#endif
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the user sign in credentials */
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
// The WiFi credentials are required for Pico W
// due to it does not have reconnect feature.
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
config.wifi.clearAP();
config.wifi.addAP(WIFI_SSID, WIFI_PASSWORD);
#endif
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
#if defined(ESP8266)
// required for large file data, increase Rx size as needed.
fbdo.setBSSLBufferSize(1024 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer size in bytes from 512 - 16384 */);
#endif
/* Assign download buffer size in byte */
// Data to be downloaded will read as multiple chunks with this size, to compromise between speed and memory used for buffering.
// The memory from external SRAM/PSRAM will not use in the TCP client internal rx buffer.
config.fcs.download_buffer_size = 2048;
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
DEFAULT_FLASH_FS.begin();
}
// The Firebase Storage upload callback function
void fcsUploadCallback(FCS_UploadStatusInfo info)
{
if (info.status == fb_esp_fcs_upload_status_init)
{
Serial.printf("Uploading file %s (%d) to %s\n", info.localFileName.c_str(), info.fileSize, info.remoteFileName.c_str());
}
else if (info.status == fb_esp_fcs_upload_status_upload)
{
// Serial.printf("Uploaded %d%s, Elapsed time %d ms\n", (int)info.progress, "%", info.elapsedTime);
}
else if (info.status == fb_esp_fcs_upload_status_complete)
{
Serial.println("Upload completed\n");
FileMetaInfo meta = fbdo.metaData();
Serial.printf("Name: %s\n", meta.name.c_str());
Serial.printf("contentType: %s\n", meta.contentType.c_str());
Serial.printf("Size: %d\n", meta.size);
}
else if (info.status == fb_esp_fcs_upload_status_error)
{
Serial.printf("Upload failed, %s\n", info.errorMsg.c_str());
}
}
// The Firebase Storage download callback function
void fcsDownloadCallback(FCS_DownloadStatusInfo info)
{
if (info.status == fb_esp_fcs_download_status_init)
{
Serial.printf("Downloading file %s (%d) to %s\n", info.remoteFileName.c_str(), info.fileSize, info.localFileName.c_str());
}
else if (info.status == fb_esp_fcs_download_status_download)
{
// Serial.printf("Downloaded %d%s, Elapsed time %d ms\n", (int)info.progress, "%", info.elapsedTime);
}
else if (info.status == fb_esp_fcs_download_status_complete)
{
Serial.println("Download completed\n");
}
else if (info.status == fb_esp_fcs_download_status_error)
{
Serial.printf("Download failed, %s\n", info.errorMsg.c_str());
}
}
void loop()
{
// Firebase.ready() should be called repeatedly to handle authentication tasks.
if (Firebase.ready() && (millis() - ms > 2 * 60 * 1000 || ms == 0))
{
ms = millis();
count++;
Serial.printf("\nRun No. %d ------------------------------------\n\n", count);
File fs = DEFAULT_FLASH_FS.open("/media.mp4", "r");
if (fs)
{
Serial.printf("File media.mp4 size before upload %d\n", (int)fs.size());
fs.close();
}
Serial.println("\nUpload file...\n");
// MIME type should be valid to avoid the download problem.
// The file systems for flash and SD/SDMMC can be changed in FirebaseFS.h.
if (!Firebase.Storage.upload(&fbdo, STORAGE_BUCKET_ID /* Firebase Storage bucket id */, "/media.mp4" /* path to local file */, mem_storage_type_flash /* memory storage type, mem_storage_type_flash and mem_storage_type_sd */, "media.mp4" /* path of remote file stored in the bucket */, "video/mp4" /* mime type */, fcsUploadCallback /* callback function */))
Serial.println(fbdo.errorReason());
Serial.println("\nDownload file...\n");
// The file systems for flash and SD/SDMMC can be changed in FirebaseFS.h.
if (!Firebase.Storage.download(&fbdo, STORAGE_BUCKET_ID /* Firebase Storage bucket id */, "media.mp4" /* path of remote file stored in the bucket */, "/media2.mp4" /* path to local file */, mem_storage_type_flash /* memory storage type, mem_storage_type_flash and mem_storage_type_sd */, fcsDownloadCallback /* callback function */))
Serial.println(fbdo.errorReason());
fs = DEFAULT_FLASH_FS.open("/media2.mp4", "r");
if (fs)
{
Serial.printf("File media2.mp4 size after downloaded %d\n", (int)fs.size());
fs.close();
}
}
}
Here is the debug info. Run No. 1 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 2 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 3 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 4 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 5 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 6 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 7 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 8 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 9 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
Run No. 10 ------------------------------------
File media.mp4 size before upload 383631
Upload file...
Uploading file /media.mp4 (383631) to media.mp4
Upload completed
Name: media.mp4
contentType: video/mp4
Size: 383631
Download file...
Downloading file media.mp4 (383631) to /media2.mp4
Download completed
File media2.mp4 size after downloaded 383631
|
Beta Was this translation helpful? Give feedback.
You should check your file properly.
The library works well on filesystem and I can confirm that there is no issue like that.