b2 is a [Backblaze B2 Cloud Storage] (https://www.backblaze.com/b2/cloud-storage.html) API client written in Go.
To use b2, import it and create an API client using your account ID and application key.
import (
"github.com/ifo/b2"
)
b2api, err := b2.CreateB2(accountID, appKey)
Create a bucket:
bucket, err := b2api.CreateBucket("kitten-pictures", AllPublic)
Upload a file:
fileReader, err := os.Open("./path/to/kitten.jpg")
// handle err
fileMeta, err := bucket.UploadFile("kitten.jpg", fileReader, nil)
Download a file:
kittenFile, err := bucket.DownloadFileByName("kitten.jpg")
// handle err
err = ioutil.WriteFile(kittenFile.Meta.Name, kittenFile.Data, 0644)
Check for an API error:
kittenFile, err := bucket.DownloadFileByName("cat.jpg")
if err != nil {
if err, ok := err.(APIError); ok {
// this is an APIError
fmt.Println(err.Message)
}
}
- Implement large file API
- Integration tests
- Example program
b2 is ISC licensed. Check out the LICENSE file.