Created
June 2, 2020 15:40
-
-
Save optlsnd/1d34926d431e57e45ee2837c92d444c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"context" | |
"github.com/uploadcare/uploadcare-go/ucare" | |
"github.com/uploadcare/uploadcare-go/upload" | |
) | |
func main() { | |
creds := ucare.APICreds{ | |
SecretKey: "demoprivatekey", | |
PublicKey: "demopublickey", | |
} | |
conf := &ucare.Config{ | |
SignBasedAuthentication: true, | |
} | |
client, err := ucare.NewClient(creds, conf) | |
if err != nil { | |
log.Fatal("creating uploadcare API client: ", err) | |
} | |
uploadSvc := upload.NewService(client) | |
checkDuplicates := upload.URLDuplicatesTrue | |
toStore := upload.ToStoreTrue | |
params := upload.FromURLParams{ | |
URL: "https://bit.ly/2LJ2xOf", | |
CheckURLDuplicates: &checkDuplicates, | |
ToStore: &toStore, | |
} | |
res, err := uploadSvc.FromURL(context.Background(), params) | |
if err != nil { | |
log.Fatal("Uploading failed: ", err) | |
} | |
info, ok := res.Info() | |
if !ok { | |
// block here until done or error | |
select { | |
case info = <-res.Done(): | |
case err = <-res.Error(): | |
} | |
} | |
if err != nil { | |
log.Fatal("Getting info failed: ", err) | |
} | |
fmt.Printf("file uploaded: %s", info) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment