From 0c7ec61e65b3d9aaed7c8cb52166ba1c88ff2a35 Mon Sep 17 00:00:00 2001 From: lzh <18320341470> Date: Wed, 16 Jul 2025 14:12:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91oss=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oss_tool/aliyun_oss.go | 15 +++++++++++++++ oss_tool/aliyun_oss_test.go | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/oss_tool/aliyun_oss.go b/oss_tool/aliyun_oss.go index 06e6b49..065a91d 100644 --- a/oss_tool/aliyun_oss.go +++ b/oss_tool/aliyun_oss.go @@ -145,3 +145,18 @@ func (c *ALiYunOSSClient) GetObjectToImage(bucket string, key string) (img image } return img, nil } + +// DelObject 删除对象 +func (c *ALiYunOSSClient) DelObject(bucket string, key string) (err error) { + // 创建删除对象的请求 + request := &oss.DeleteObjectRequest{ + Bucket: oss.Ptr(bucket), // 存储空间名称 + Key: oss.Ptr(key), // 对象名称 + } + // 执行删除对象的操作并处理结果 + _, err = c.ossClient.DeleteObject(context.TODO(), request) + if err != nil { + return err + } + return nil +} diff --git a/oss_tool/aliyun_oss_test.go b/oss_tool/aliyun_oss_test.go index b94302e..637c244 100644 --- a/oss_tool/aliyun_oss_test.go +++ b/oss_tool/aliyun_oss_test.go @@ -73,3 +73,16 @@ func TestALiYunOSSClient_GetObjectToImage(t *testing.T) { t.Log(img) } } + +func TestALiYunOSSClient_DelObject(t *testing.T) { + err := client.NewAliYunOSS() + if err != nil { + t.Error(err) + } + err = client.DelObject("", "test/upload/bizhi2.jpg") + if err != nil { + t.Error(err) + } else { + t.Log("成功") + } +}