Skip to content

Instantly share code, notes, and snippets.

@optlsnd
Created June 2, 2020 15:40
Show Gist options
  • Save optlsnd/1d34926d431e57e45ee2837c92d444c6 to your computer and use it in GitHub Desktop.
Save optlsnd/1d34926d431e57e45ee2837c92d444c6 to your computer and use it in GitHub Desktop.
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