Golang API Client

Golang integration handles uploads and file operations by wrapping Uploadcare Upload API and REST API. This comprehensive API client lets you use most of the Uploadcare features from within your Golang app.

GitHub →

Features

Uploading (Upload API):

  • Upload files from local storage and URLs (up to 5 TB)
  • Multipart uploading for large files
  • Uploading network to speed uploading jobs (like CDN)

File management (REST API):

  • Get file info and perform various operations (store/delete/copy) with them
  • Work with groups of files
  • Get info about account project
  • Manage webhooks
  • Convert documents
  • Encode and transform videos

Image processing (URL API):

  • Compression
  • Geometry
  • Colors
  • Definition
  • Image and text overlays
  • Rotations
  • Recognition
  • File info
  • Proxy (fetch)

Security features:

  • Secure authentication
  • Secure uploads (signed uploads)
  • Secure delivery (signed URLs)

Requirements

  • go1.13

Installation

Install uploadcare-go with:

go get -u -v github.com/uploadcare/uploadcare-go/...

Then import it using:

1import (
2 "github.com/uploadcare/uploadcare-go/ucare"
3 "github.com/uploadcare/uploadcare-go/file"
4 "github.com/uploadcare/uploadcare-go/group"
5 "github.com/uploadcare/uploadcare-go/upload"
6 "github.com/uploadcare/uploadcare-go/conversion"
7)

Configuration

Creating a client:

1creds := ucare.APICreds{
2 SecretKey: "your-project-secret-key",
3 PublicKey: "your-project-public-key",
4}
5
6conf := &ucare.Config{
7 SignBasedAuthentication: true,
8 APIVersion: ucare.APIv06,
9}
10
11client, err := ucare.NewClient(creds, conf)
12if err != nil {
13 log.Fatal("creating uploadcare API client: %s", err)
14}

Usage example

For a comprehensive list of examples, check out the Upload API documentation.

Getting a list of files:

1fileSvc := file.NewService(client)
2
3listParams := file.ListParams{
4 Stored: ucare.Bool(true),
5 OrderBy: ucare.String(file.OrderBySizeAsc),
6}
7
8fileList, err := fileSvc.List(context.Background(), listParams)
9if err != nil {
10 // handle error
11}
12
13// getting IDs of the files
14ids := make([]string, 0, 100)
15for fileList.Next() {
16 finfo, err := fileList.ReadResult()
17 if err != nil {
18 // handle error
19 }
20
21 ids = append(ids, finfo.ID)
22}

Getting file info:

1fileID := ids[0]
2file, err := fileSvc.Info(context.Background(), fileID)
3if err != nil {
4 // handle error
5}
6
7if file.IsImage {
8 h := file.ImageInfo.Height
9 w := file.ImageInfo.Width
10 fmt.Printf("image size: %dx%d\n", h, w)
11}

Uploading a file:

1f, err := os.Open("file.png")
2if err != nil {
3 // handle error
4}
5
6uploadSvc := upload.NewService(client)
7
8params := upload.FileParams{
9 Data: f,
10 Name: f.Name(),
11 ContentType: "image/png",
12}
13fID, err := uploadSvc.File(context.Background(), params)
14if err != nil {
15 // handle error
16}

Full documentation

Read the full documentation on GitHub.

  • Integration with Rust