writing mqtt payload to spiffs file I'm trying to write the payload of a MQTT message into a file in the SPIFFS file system of my esp32 board. I've tried this:

if(file.print((long)payload)) {
   Serial.println("File was written");
}else {
   Serial.println("File write failed");
}


payload is a byte* and file was opened in the setup() function like:

File file;
if(!SPIFFS.exists("/testfile")){
  file = SPIFFS.open("/testfile", "r+");
}


I always get an error when writing to it telling me that the file write failed. Is this the correct approach for what I'm trying to accomplish?
Use file.write(payload, length); for byte array. length should be the count of payload bytes, not the size of the payload array.

print and write return the count of bytes written. It is not meaningful to use the return value as boolean.