ESP8266 Upload Files on Flash system doesnt work

So im doing a project and i need to upload files into my flash system and I already setup everything on my PlatformIO. So when i I click build Filesystem then i Click Upload images then the procedure succeeds but when i check for files in my SPIFFS there are no images uploaded to it. So I do it a second time and it works (TRIED MULTIPLE TIMES ONLY WORKS ON SECOND TIME). I check for the image and now its on my SPIFFS so when i try to do something with the image it seems that is corrupted or something because it never uploads unto the web and cant draw it on my TFT LCD(all pixelated but at correct resolution). Ive tried to upload an image from the web unto my SPIFFS it works perfectly and it can be drawn on my LCD. Also The uploading Image tool did work before with the same image but when i deleted it from the flash system (with an arduino program) then reuploaded it this problem began. So I need help to figure out why it doesnt work or a way that I can upload this jpg file in my flash system.

Can you provide a minimal project that reproduces the problem?

Which “PLATOFRM: Espressif32 (x.y.z)” version is shown in the build log?

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <FS.h>  // Include the SPIFFS library

const char* ssid = "";
const char* password = "";

ESP8266WebServer server(80);  // Create a webserver object that listens for HTTP request on port 80

void setup() {
  Serial.begin(115200);

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Mount SPIFFS
  if (!SPIFFS.begin()) {
    Serial.println("Error mounting SPIFFS");
    return;
  }

  // Define endpoints
  server.on("/", HTTP_GET, handleRoot);
  server.on("/tiastoopid.jpg", HTTP_GET, handleImage);
  
  server.begin();
}

void handleRoot() {
  String html = "<html><body><img src=\"/tiastoopid.jpg\" alt=\"Image\"></body></html>";
  server.send(200, "text/html", html);
}

void handleImage() {
  File file = SPIFFS.open("/tiastoopid.jpg", "r");  // Replace with your image path
  if (!file) {
    server.send(404, "text/plain", "File not found");
    return;
  }
  server.streamFile(file, "image/jpeg");
  file.close();
}

void loop() {
  server.handleClient();  // Handle client requests
}

Espressif 8266 (4.2.1) > WeMos D1 R2 and mini

Next to the program code, we’d also need to see your platformio.ini.

No its because I use the ArduinoIDE to upload my code into my ESP8266 do you think that is a problem?

[env:d1_mini]

platform = espressif8266

board = d1_mini

framework = arduino

monitor_speed = 115200

Huh? So you upload the sketch code from the Arduino IDE, then use PlatformIO to do the filesystem upload? But never do both things from the same IDE?

No because i got too lazy downloading all the libraries but that is not the point.

Well it is very much the point, if you use differing Tools settings in the Arduino IDE than what PlatformIO is configured for, such as board, flash size, partition table, etc., then it can happen that PlatformIO thinks the SPIFFS filesystem address is somewhere else compared to the Arduino-IDE compiled firmware, and thus nothing will work.

See docs for configuration.

https://docs.platformio.org/en/latest/platforms/espressif8266.html