-
-
Save fd0/180efcf728398d991a1fa9c903a12f54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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