-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (57 loc) · 1.56 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"bytes"
"fmt"
"os"
"time"
"github.com/AshokShau/catbox"
)
func main() {
// Open the image file
filePath := "example/img.png"
file, err := os.Open(filePath)
if err != nil {
fmt.Printf("Error opening file: %v\n", err)
return
}
defer file.Close()
// Read the file into a buffer
var fileBuffer bytes.Buffer
if _, err = fileBuffer.ReadFrom(file); err != nil {
fmt.Printf("Error reading file: %v\n", err)
return
}
// Set the file name and user hash (if any)
fileName := "image.png"
userHash := "" // Optional: Set your user hash if you have one
// Set the timeout duration
timeout := 10 * time.Second
// Upload the file to CatBox
response, err := catbox.UploadFile(&fileBuffer, fileName, timeout, userHash)
if err != nil {
fmt.Printf("Upload to CatBox failed: %v\n", err)
return
}
fmt.Println("Upload to CatBox successful! Response:", response)
// Re-open the file for the second upload
file, err = os.Open(filePath)
if err != nil {
fmt.Printf("Error opening file: %v\n", err)
return
}
defer file.Close()
// Reset the file buffer and read the file again
fileBuffer.Reset()
if _, err = fileBuffer.ReadFrom(file); err != nil {
fmt.Printf("Error reading file: %v\n", err)
return
}
// Upload the file to LitterBox
duration := "1h" // Duration for which the file should be stored
response, err = catbox.UploadToLitterBox(&fileBuffer, fileName, duration, timeout)
if err != nil {
fmt.Printf("Upload to LitterBox failed: %v\n", err)
return
}
fmt.Println("Upload to LitterBox successful! Response:", response)
}