Transloadit's official Go SDK, maintained by the community
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
examples
fixtures
scripts
.gitignore
.travis.yml
LICENSE
Makefile
README.md
Vagrantfile
assembly.go
assembly_test.go
notification.go
notification_test.go
template.go
template_test.go
transloadit.go
transloadit_test.go
version.go
wait.go
wait_test.go

README.md

Build Status Coverage Status

go-sdk

A Go Integration for Transloadit's file uploading and encoding service

Intro

Transloadit is a service that helps you handle file uploads, resize, crop and watermark your images, make GIFs, transcode your videos, extract thumbnails, generate audio waveforms, and so much more. In short, Transloadit is the Swiss Army Knife for your files.

This is a Go SDK to make it easy to talk to the Transloadit REST API.

Install

go get gopkg.in/transloadit/go-sdk.v1

The Go SDK requires Go 1.7 or higher.

Usage

package main

import (
	"context"
	"fmt"

	"gopkg.in/transloadit/go-sdk.v1"
)

func main() {
	// Create client
	options := transloadit.DefaultConfig
	options.AuthKey = "YOUR_TRANSLOADIT_KEY"
	options.AuthSecret = "YOUR_TRANSLOADIT_SECRET"
	client := transloadit.NewClient(options)

	// Initialize new assembly
	assembly := transloadit.NewAssembly()

	// Add a file to upload
	assembly.AddFile("image", "/PATH/TO/FILE.jpg")

	// Add instructions, e.g. resize image to 75x75px
	assembly.AddStep("resize", map[string]interface{}{
		"robot":           "/image/resize",
		"width":           75,
		"height":          75,
		"resize_strategy": "pad",
		"background":      "#000000",
	})

	// Start the upload
	info, err := client.StartAssembly(context.Background(), assembly)
	if err != nil {
		panic(err)
	}

	// All files have now been uploaded and the assembly has started but no
	// results are available yet since the conversion has not finished.
	// WaitForAssembly provides functionality for polling until the assembly
	// has ended.
	info, err = client.WaitForAssembly(context.Background(), info)
	if err != nil {
		panic(err)
	}

	fmt.Printf("You can view the result at: %s\n", info.Results["resize"][0].SSLURL)
}

Example

For fully working examples on how to use templates, non-blocking processing and more, take a look at examples/.

Documentation

See Godoc for full API documentation.

License

MIT Licensed