Uploading Files to ESP32 Using SPIFFS with PlatformIO and Arduino IDE
By KennyT99 05\30\2025

Uploading Files to ESP32 Using SPIFFS with PlatformIO and Arduino IDE

How to Use SPIFFS to Store and Read Files on a Microcontroller

Learn to embed text files, images, and other assets into the onboard memory of your ESP32 using SPIFFS

SPIFFS (SPI Flash File System) enables developers working with microcontrollers like the ESP32'to store files directly on the device's onboard flash memory.
This is incredibly useful for storing static assets such as configuration files, credentials, images, or text that the microcontroller can read at runtime.

In this tutorial, we'll show how to upload a file to the ESP32 using Visual Studio Code with the PlatformIO plugin. The same approach can also be used in the Arduino IDE, which offers a similar SPIFFS file upload feature.

Why Use SPIFFS?

Storing data directly on your microcontroller via SPIFFS avoids hardcoding values or relying on external memory modules. You can upload:

  • Text configuration files (e.g., Wi-Fi credentials)
  • Images
  • MP3/MP4 files
  • Or any file that your microcontroller logic can interpret

Steps to Upload a SPIFFS File Using PlatformIO

  1. Create a folder named data in the root directory of your PlatformIO project.
  2. Place the file(s) you wish to upload into the data folder. This could be a text file like config.txt or an image.
  3. Use the PlatformIO upload task to flash the data:
    PlatformIO > Upload File System image
    This will copy the contents of the data folder into the ESP32's internal flash memory.

Reading the SPIFFS File in Code

After uploading, your ESP32 sketch can interact with the file system:


if (!SPIFFS.begin(true)) {
    Serial.println("SPIFFS Mount Failed");
    return;
}

File file = SPIFFS.open("/config.txt");
if (!file) {
    Serial.println("Failed to open file");
    return;
}

while (file.available()) {
    Serial.write(file.read());
}
file.close();

Using Arduino IDE

The Arduino IDE also supports SPIFFS uploads via the ESP32 Sketch Data Upload plugin. Once installed, you can:

  1. Create a data folder in your project directory.
  2. Place your files in that folder.
  3. Go to Tools > ESP32 Sketch Data Upload to flash the files to SPIFFS.

Video Tutorial

For visual learners, check out this helpful walkthrough:

ESP32 SPIFFS Library Tutorial by DIYProjects.io

Additional Page(s):

Download or View Full PDF Guide

You can view or download the complete SPIFFS upload tutorial PDF here: