Skip to content

Instantly share code, notes, and snippets.

@fd0

fd0/-

Created May 13, 2017 12:31
Show Gist options
  • Save fd0/180efcf728398d991a1fa9c903a12f54 to your computer and use it in GitHub Desktop.
Save fd0/180efcf728398d991a1fa9c903a12f54 to your computer and use it in GitHub Desktop.
package main
import (
crand "crypto/rand"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
minio "github.com/minio/minio-go"
)
func main() {
data := make([]byte, 120000)
_, err := io.ReadFull(crand.Reader, data)
if err != nil {
panic(err)
}
tempfile, err := ioutil.TempFile("", "minio-go-upload-test-")
if err != nil {
panic(err)
}
if err = os.Remove(tempfile.Name()); err != nil {
panic(err)
}
if err = ioutil.WriteFile(tempfile.Name(), data, 0600); err != nil {
panic(err)
}
if _, err = tempfile.Seek(0, 0); err != nil {
panic(err)
}
client, err := minio.New("s3.amazonaws.com", os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), false)
if err != nil {
panic(err)
}
client.TraceOn(os.Stderr)
name := fmt.Sprintf("test-file-%v", rand.Uint32())
fi, err := client.StatObject(os.Getenv("BUCKET"), name)
if err != nil {
panic(err)
}
fmt.Printf("stat: %v\n", fi)
n, err := client.PutObject(os.Getenv("BUCKET"), name, tempfile, "binary/octet-stream")
fmt.Printf("wrote %d bytes to %v err %v\n", n, name, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment