-
Notifications
You must be signed in to change notification settings - Fork 114
/
upload.go
44 lines (35 loc) · 925 Bytes
/
upload.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
package anonfiles
import (
"encoding/json"
"fmt"
"io"
"github.com/Mikubill/transfer/apis"
"github.com/Mikubill/transfer/apis/methods"
)
const upload = "https://api.anonfiles.com/upload"
func (b *anon) DoUpload(name string, size int64, file io.Reader) error {
body, err := methods.MultipartUpload(methods.MultiPartUploadConfig{
FileSize: size,
FileName: name,
FileReader: file,
Debug: apis.DebugMode,
Endpoint: upload,
})
if err != nil {
return fmt.Errorf("upload returns error: %s", err)
}
var resp uploadResp
err = json.Unmarshal(body, &resp)
if err != nil {
return fmt.Errorf("unmarshal returns error: %s", err)
}
if !resp.Status {
return fmt.Errorf("upload returns error: %s", resp.Error.Message)
}
b.resp = resp.Data.File.URL.Full
return nil
}
func (b *anon) PostUpload(string, int64) (string, error) {
fmt.Printf("Download Link: %s\n", b.resp)
return b.resp, nil
}