查看PDF

批量删除对象

更新时间: 2019-03-13 10:20

功能说明

批量删除指定桶中的多个对象。

方法定义

  1. func (obsClient ObsClient) DeleteObjects(input *DeleteObjectsInput) (output *DeleteObjectsOutput, err error)

使用带授权信息URL的方法定义

  1. func (obsClient ObsClient) DeleteObjectsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *DeleteObjectsOutput, err error)

请求参数


参数名

类型

约束

input

*DeleteObjectsInput

必选

返回结果


参数名

类型

output

*DeleteObjectsOutput

err

error

代码样例

  1. func main() {
  2. input := &obs.DeleteObjectsInput{}
  3. input.Bucket = "bucketname"
  4. var objects [3]obs.ObjectToDelete
  5. objects[0] = obs.ObjectToDelete{Key: "key1"}
  6. objects[1] = obs.ObjectToDelete{Key: "key2"}
  7. objects[2] = obs.ObjectToDelete{Key: "key3"}
  8.  
  9. input.Objects = objects[:]
  10. output, err := obsClient.DeleteObjects(input)
  11. if err == nil {
  12. fmt.Printf("RequestId:%s\n", output.RequestId)
  13. for index, deleted := range output.Deleteds {
  14. fmt.Printf("Deleted[%d]-Key:%s, VersionId:%s\n", index, deleted.Key, deleted.VersionId)
  15. }
  16. for index, err := range output.Errors {
  17. fmt.Printf("Error[%d]-Key:%s, Code:%s\n", index, err.Key, err.Code)
  18. }
  19. } else {
  20. if obsError, ok := err.(obs.ObsError); ok {
  21. fmt.Println(obsError.Code)
  22. fmt.Println(obsError.Message)
  23. } else {
  24. fmt.Println(err)
  25. }
  26. }
  27. }

父主题:对象相关接口