ref: 40530e831cee9d9a6eea7c61394eed0b5ea182fa
parent: edb969542027b435ece5aae776f0de3c6ff5856a
author: penny <penny@limitedideas.org>
date: Fri Oct 3 17:27:44 EDT 2025
use file Reader for media upload
--- a/filehandler.go
+++ b/filehandler.go
@@ -1,7 +1,6 @@
package main
import (
- "bytes"
"context"
"fmt"
"io"
@@ -147,13 +146,13 @@
// Return a byte array and error given a filepath
// Expands ~ and environmental variables
-func loadFile(path string) (*[]byte, error) {+func loadFile(path string) (*os.File, error) {path = expandDir(path)
- data, err := os.ReadFile(path)
+ file, err := os.Open(path)
if err != nil { return nil, fmt.Errorf("read error: %s: %s", path, err)}
- return &data, nil
+ return file, nil
}
// Upload media by path to the mastodon server
@@ -165,8 +164,7 @@
config := sam.rl.GetConfig()
config.Prompt = "Image description: "
description, _ := sam.rl.ReadLineWithConfig(config)
- reader := bytes.NewReader(*file)
- media := &mastodon.Media{File: reader, Description: description}+ media := &mastodon.Media{File: file, Description: description}attachment, err := sam.client.UploadMediaFromMedia(context.Background(), media)
sam.attachments = append(sam.attachments, attachment)
if err != nil {--
⑨