try naming form for link to img, no dice
parent
fade4467d6
commit
2b6acc51fb
|
|
@ -12,7 +12,7 @@
|
||||||
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
"RefreshURI": "https://api.imgur.com/oauth2/token",
|
||||||
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
"RefreshFormat": "refresh_token=%s\u0026client_id=%s\u0026client_secret=%s\u0026grant_type=refresh_token",
|
||||||
"RefreshMethod": "POST",
|
"RefreshMethod": "POST",
|
||||||
"UploadURI": "https://api.imgur.com/3/image",
|
"UploadURI": "https://api.imgur.com/3/image?name=something.jpeg",
|
||||||
"UploadMethod": "POST"
|
"UploadMethod": "POST"
|
||||||
},
|
},
|
||||||
"Maps": {
|
"Maps": {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/truckstop/config"
|
"local/truckstop/config"
|
||||||
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -30,9 +32,17 @@ func refreshToken() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadImage(b []byte) (string, error) {
|
func uploadImage(b []byte) (string, error) {
|
||||||
|
images := config.Get().Images
|
||||||
buff := bytes.NewBuffer(nil)
|
buff := bytes.NewBuffer(nil)
|
||||||
writer := multipart.NewWriter(buff)
|
writer := multipart.NewWriter(buff)
|
||||||
part, err := writer.CreateFormFile("image", "name")
|
name := "name"
|
||||||
|
if u, err := url.Parse(images.UploadURI); err != nil {
|
||||||
|
} else if s, ok := u.Query()["name"]; !ok {
|
||||||
|
} else {
|
||||||
|
name = s[0]
|
||||||
|
log.Printf("found name in upload uri: %s", name)
|
||||||
|
}
|
||||||
|
part, err := writer.CreateFormFile("image", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +53,6 @@ func uploadImage(b []byte) (string, error) {
|
||||||
}
|
}
|
||||||
writer.Close()
|
writer.Close()
|
||||||
|
|
||||||
images := config.Get().Images
|
|
||||||
request, err := http.NewRequest(
|
request, err := http.NewRequest(
|
||||||
images.UploadMethod,
|
images.UploadMethod,
|
||||||
images.UploadURI,
|
images.UploadURI,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue