S3
#
MinIO
#
Go
#
PutObject
#
func postUpload(c *gin.Context) {
file, _ := c.FormFile("file")
log.Println(file.Filename)
ctx := context.Background()
endPoint := "IPアドレス:9000"
accessKeyID := "アクセスキー"
secretAccessKey :="シークレットアクセスキー"
useSSL := false
minioClient, err := minio.New(endPoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
Secure: useSSL,
})
if err != nil {
log.Fatalln(err)
}
log.Printf("%#v\n", minioClient)
bucketName := "photo"
fp, err := file.Open()
if err != nil {
log.Fatalln(err)
}
info, err := minioClient.PutObject(ctx, bucketName,
file.Filename,
fp,
file.Size,
minio.PutObjectOptions{})
if err != nil {
log.Fatalln(err)
}
log.Printf("Uploaded %s %d\n", file.Filename, info.Size)
}
Python
#
fput_object
#
from minio import Minio
from minio.error import S3Error
def main():
# Create a client with the MinIO server playground, its access key
# and secret key.
client = Minio(
"IPアドレス:9000",
access_key="アクセスキー",
secret_key="シークレットアクセスキー",
secure=False,
)
found = client.bucket_exists("photo")
if not found:
client.make_bucket("photo")
else:
print("Bucket 'photo' already exists")
client.fput_object(
"photo", "P6152232.jpg", "/workspaces/sandbox/python/minio/P6152232.jpg",
)
if __name__ == "__main__":
try:
main()
except S3Error as exc:
print("error occurred.", exc)