@@ 2,6 2,9 @@
**Note:** Please add newest entries on top. Use ISO date format YYYY-MM-DD and markdown formatting.
+## 2024-02-07
+- feat: Read file to memory as a byte array.
+
## 2024-01-28
- feat: Continue implementing file attachement logic.
- feat: Start calling the `attachImageToNotification` function.
@@ 496,17 496,17 @@ func attachImageToNotification(notificationToSend *Notification, validConfigurat
logger.Fatalf("File %s is bigger than %d bytes, which is the upper limit imposed by Pushover API. Try with a smaller image file.", fileInformation.Name(), validConfigurationOptions.maximumFileSizeInBytes)
}
- // Let's try adding the image.
- imageFile, err := os.Open(notificationToSend.imageAttachmentPath)
-
- defer imageFile.Close() // Let's close the file automatically.
+ // Let's read the file into a byte array, so we can convert it to BASE64.
+ fileContents := make([]byte, fileInformation.Size())
+
+ fileContents, err = os.ReadFile(notificationToSend.imageAttachmentPath)
// If we can't open the file, we catch the problem here.
if err != nil {
- logger.Fatalf("Opening file returned an error (error is %s).", err)
+ logger.Fatalf("Reading file returned an error (error is %s).", err)
}
- logger.Debugf("The file %s has been opened successfully.", fileInformation.Name())
+ logger.Debugf("The file %s has been read successfully.", fileInformation.Name())
}
// This function pretty prints application state.