ESP32 SD card uploading file to Firebase Storage. #128
Replies: 2 comments 2 replies
-
There is no bug but your logic problem. You do not open or touch the file that used by the If you do that, you should close that file prior to upload and download. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Library does not handle your file directly but though the You are corresponding to open and remove file in fileCalllback. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
`#include <SPI.h>
#include <SD.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <FirebaseClient.h>
// Define Wi-Fi credentials
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
// Firebase credentials
#define API_KEY ""
#define USER_EMAIL ""
#define USER_PASSWORD ""
#define STORAGE_BUCKET_ID ""
// Firebase configuration
UserAuth user_auth(API_KEY, USER_EMAIL, USER_PASSWORD, 3000);
FirebaseApp app;
WiFiClientSecure ssl_client;
DefaultNetwork network;
using AsyncClient = AsyncClientClass;
AsyncClient aClient(ssl_client, getNetwork(network));
Storage storage;
AsyncResult aResult_no_callback;
bool taskCompleted = false;
File myFile;
// Function declarations
void printResult(AsyncResult &aResult);
void printError(int code, const String &msg);
void fileCallback(File &file, const char *filename, file_operating_mode mode);
// File configuration
#define FILE_NAME ""
FileConfig upload_file(FILE_NAME, fileCallback);
void setup()
{
// Start the serial communication
Serial.begin(115200);
}
void loop()
{
app.loop();
storage.loop();
}
void printResult(AsyncResult &aResult)
{
if (aResult.isEvent())
{
Firebase.printf("Event task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.appEvent().message().c_str(), aResult.appEvent().code());
}
}
void printError(int code, const String &msg)
{
Firebase.printf("Error, msg: %s, code: %d\n", msg.c_str(), code);
}
void fileCallback(File &file, const char *filename, file_operating_mode mode)
{
switch (mode)
{
case file_mode_open_read:
myFile = SD.open(filename, FILE_READ);
if (!myFile)
{
Serial.println("Failed to open file for reading");
}
else
{
Serial.println("File opened for reading");
}
break;
case file_mode_open_write:
myFile = SD.open(filename, FILE_WRITE);
if (!myFile)
{
Serial.println("Failed to open file for writing");
}
else
{
Serial.println("File opened for writing");
}
break;
case file_mode_open_append:
myFile = SD.open(filename, FILE_APPEND);
if (!myFile)
{
Serial.println("Failed to open file for appending");
}
else
{
Serial.println("File opened for appending");
}
break;
case file_mode_remove:
if (SD.remove(filename))
{
Serial.println("File removed");
}
else
{
Serial.println("Failed to remove file");
}
break;
default:
break;
}
file = myFile;
}
`
I have faced a bug that when I comment the line "File file = SD.open(FILE_NAME, FILE_READ);" under the void loop(), error of (-104) occur but when I added the line back, the upload can be successfully done. Anyone knows why?
Beta Was this translation helpful? Give feedback.
All reactions