From 4af950f313b3a12aeed3c928efad4bf1dac8c03e Mon Sep 17 00:00:00 2001 From: jojoliang Date: Tue, 27 Apr 2021 19:50:33 +0800 Subject: [PATCH] add directory demo --- example/object/directory.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/example/object/directory.go b/example/object/directory.go index 57a2af1..73e7fdf 100644 --- a/example/object/directory.go +++ b/example/object/directory.go @@ -59,4 +59,36 @@ func main() { // 删除文件夹 _, err = c.Object.Delete(context.Background(), name) log_status(err) + + // 上传到虚拟目录 + dir := "exampledir/" + filename := "exampleobject" + key := dir + filename + f := strings.NewReader("test file") + _, err = c.Object.Put(context.Background(), key, f, nil) + log_status(err) + + // 删除文件夹内所有文件 + var marker string + opt := &cos.BucketGetOptions{ + Prefix: dir, + MaxKeys: 1000, + } + isTruncated := true + for isTruncated { + opt.Marker = marker + v, _, err := c.Bucket.Get(context.Background(), opt) + if err != nil { + log_status(err) + break + } + for _, content := range v.Contents { + _, err = c.Object.Delete(context.Background(), content.Key) + if err != nil { + log_status(err) + } + } + isTruncated = v.IsTruncated + marker = v.NextMarker + } }