官方中文 http://www.minio.org.cn/
下载
客户端http://dl.minio.org.cn/client/mc/release/windows-amd64/mc.exe
服务器端 http://dl.minio.org.cn/server/minio/release/windows-amd64/minio.exe
windows
minio.exe server D:\Photos
linux

wget   http://dl.minio.org.cn/server/minio/release/linux-amd64/minio
chmod +x minio
./minio server --address :9000  --console-address :9002 /mnt/data

wget    http://dl.minio.org.cn/client/mc/release/linux-amd64/mc
chmod +x mc
./mc --help
- 修改密码
/root/miniodata/.minio.sys/config 里面文件
  • golang
minio "github.com/minio/minio-go/v7"
s3,_:=minio.New("localhost:9000", &minio.Options{
        Creds:  credentials.NewStaticV4("P55OPS3GBBSGO0GBB8VH", "VjTfrznY0PB+BghMU5Tgtl6GU52zA7oOHjVGYyyI", ""),
        Secure: false,//是否ssl
    })
    ctx := context.Background()
    g.Dump(s3.ListBuckets(ctx))
    s3.MakeBucket(ctx, "xxx1", minio.MakeBucketOptions{Region: "us-east-1"})//创建桶
isok,_:=s3.BucketExists(ctx,"xxx1")//是否存在桶
fmt.Println(isok)
    s3.RemoveBucket(ctx, "x111")//删除桶
    ui, _ := s3.CopyObject(ctx, minio.CopyDestOptions{Bucket: "xxx1",Object: "1.ini",ReplaceTags: true,
        UserTags: map[string]string{
            "Tag1": "Value1",
            "Tag2": "Value2",
        },}, minio.CopySrcOptions{Bucket: "localimg",Object: "images/2.ini"})//复制文件
    fmt.Println(ui.Key)
    s3.FGetObject(ctx, "xxx1", "1.ini", "1.csv", minio.GetObjectOptions{})//下载
    s3.FPutObject(ctx, "xxx1", "qq.ini", "1.csv", minio.PutObjectOptions{
        ContentType: "application/csv",
    })//上传

    ss,_:=s3.GetBucketPolicy(ctx, "abc")//获取权限
    fmt.Println(ss)

    reader, _ := s3.GetObject(ctx, "xxx1", "1.ini", minio.GetObjectOptions{})
    defer reader.Close()
    localFile, _ := os.Create("11.ini")
    defer localFile.Close()
    stat, _ := reader.Stat()
    io.CopyN(localFile, reader,stat.Size)//下载

    for mu :=range s3.ListObjects(ctx, "localimg",minio.ListObjectsOptions{//列出文件
        UseV1:     true,
        Prefix:    "images",
        Recursive: true,
    }){
        fmt.Println(mu.Key)
    }
    purl, _ := s3.PresignedPutObject(ctx, "localimg", "images/401.089007e7.gif",time.Second*24*3600*2)//生成url
    fmt.Println(purl)
cx,_:=os.Open("qq/1.jpg")
defer cx.Close()
    s3.PutObject(ctx, "xxx1", "2.gif",cx ,-1, minio.PutObjectOptions{ContentType: "application/octet-stream"})
    s3.RemoveObject(ctx, "xxx1", "1.ini", minio.RemoveObjectOptions{})//删除1个

    objectsCh := make(chan minio.ObjectInfo)
    go func() {
        defer close(objectsCh)
        opts := minio.ListObjectsOptions{Prefix: "my-prefixname", Recursive: true}
        for object := range s3.ListObjects(ctx, "xxe", opts) {
            objectsCh <- object
        }
    }()
    s3.RemoveObjects(ctx, "xxe", objectsCh, minio.RemoveObjectsOptions{})//删除多个

    t,_:= tags.MapToBucketTags(map[string]string{
        "Tag1": "Value1",
        "Tag2": "Value2",
    })
    s3.SetBucketTagging(ctx, "xxx1", t)

    policy := `{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":["*"]},"Action":["s3:GetBucketLocation","s3:ListBucket","s3:ListBucketMultipartUploads"],"Resource":["arn:aws:s3:::xxx1"]},{"Effect":"Allow","Principal":{"AWS":["*"]},"Action":["s3:AbortMultipartUpload","s3:DeleteObject","s3:GetObject","s3:ListMultipartUploadParts","s3:PutObject"],"Resource":["arn:aws:s3:::xxx1/*"]}]}`

    s3.SetBucketPolicy(ctx, "xxx1", policy)//设置public

ii:=strings.NewReader("写入字符串到桶")    s3.PutObject(ctx,"xxx1","qq.txt",ii,-1,minio.PutObjectOptions{ContentType:"text/plain"})
    ss,_:=s3.GetObject(ctx,"xxx1","qq.txt",minio.GetObjectOptions{})
    b,_:=io.ReadAll(ss)
    fmt.Printf("%s",b)


github.com/minio/minio-go
    m,_:=minio.New("localhost:9000", "P55OPS3GBBSGO0GBB8VH", "VjTfrznY0PB+BghMU5Tgtl6GU52zA7oOHjVGYyyI", false)
    //m,_:=minio.New("localhost:9000", "minioadmin", "minioadmin", false)
g.Dump(m.ListBuckets())//获取桶列表slice
m.MakeBucket("abcd","us-east-1")//创建桶
isok,_:=m.BucketExists("abc")//桶是否存在
fmt.Println(isok)
m.RemoveBucket("abcd")//删除桶

    doneCh := make(chan struct{})
    defer close(doneCh)
for msg:=range m.ListObjectsV2("localimg","images",true,doneCh){
        fmt.Println(msg.Key)
    }
m.FGetObject("localimg","images/profile.9ea78635.jpg","./qq/1.jpg",minio.GetObjectOptions{})//下载文件

    file,_:= os.Open("db.db")
    defer file.Close()
    m.PutObject("localimg","images/a.db",file,-1,minio.PutObjectOptions{
        UserMetadata: map[string]string{"title":"标题"},
    })//上传
    m.FPutObject("localimg","images/2.ini","./1.ini",minio.PutObjectOptions{})//上传

    newsrc,_:=minio.NewDestinationInfo("abc","img/a.db",nil,nil)
    m.CopyObject(newsrc,minio.NewSourceInfo("localimg","images/a.db",nil))//复制内容

    objInfo, _ := m.StatObject("abc", "img/a.db", minio.StatObjectOptions{})
    fmt.Println(objInfo.ContentType)//文件元信息

    m.RemoveObject("abc","1")//删除对象1个

    objectsCh := make(chan string)//清空
    go func() {
        defer close(objectsCh)
        for object := range m.ListObjects("abc", "", true, nil) {
            if object.Err != nil {
                log.Fatalln(object.Err)
            }
            objectsCh <- object.Key
        }
    }()
    for rErr := range m.RemoveObjects("abc", objectsCh) {//删除多个
        fmt.Println("Error detected during deletion: ", rErr)
    }

    urls, _ := m.PresignedPutObject("localimg", "images/401.089007e7.gif", time.Second*24*3600*2)//生成url
    fmt.Println(urls.Host+urls.Path)

    q,_:=m.GetBucketPolicy("localimg")//读取权限
    g.Dump(q)

    m.SetBucketPolicy("abc","readwrite")//设置权限
  • php

    ~
    composer require aws/aws-sdk-php

    require ‘vendor/autoload.php’;
    use Aws\Exception\AwsException;
    $s3 = new Aws\S3\S3Client([

      'version' => 'latest',
      'region'  => 'us-east-1',
      'endpoint' => 'http://localhost:9000',
      'use_path_style_endpoint' => true,
      'credentials' => [
              'key'    => 'P55OPS3GBBSGO0GBB8VH',
              'secret' => 'VjTfrznY0PB+BghMU5Tgtl6GU52zA7oOHjVGYyyI',
          ],

    ]);

// 发送PutObject请求并获得result对象
$insert = $s3->putObject([
‘Bucket’ => ‘xxx1’,
‘Key’ => ‘testkey’,
‘Body’ => ‘Hello from MinIO!!’
]);

// 下载文件的内容
$retrive = $s3->getObject([
‘Bucket’ => ‘xxx1’,
‘Key’ => ‘testkey’,
‘SaveAs’ => ‘testkey_local’
]);

// 通过索引到结果对象来打印结果的body。
echo $retrive[‘Body’];

$result = $s3->listBuckets();
$array = $result->toArray();
//dump($array);
$names = $result->search(‘Buckets[].Name’);//只返回桶
dump($names);

try {
$s3->createBucket([‘Bucket’ => ‘abcd’]);//桶需要至少四个字母
}catch (AwsException $exception){}

$results = $s3->getPaginator(‘ListObjects’, [‘Bucket’ => ‘localimg’]);
foreach ($results->search(‘Contents[].Key’) as $key) {
echo $key . “\n”;
}
$list = $s3->listObjects([“Bucket”=>”localimg”,”key”=>”images”]);
foreach ($list[‘Contents’] as $object) {
echo $object[‘Key’] . “\n”;
}

$s3->putObject([
‘Bucket’ =>”abcd”,
‘Key’ => “1.jpg”,
‘SourceFile’ => “1.webp”,
]);//上传文件
$resp = $s3->getObjectUrl(‘localimg’, ‘images/profile.9ea78635.jpg’);
dump($resp);//获取url

~

文档更新时间: 2023-07-08 20:14   作者:Yoby