九游平台/ 对象存储服务 obs/ sdk参考/ go/ / 分段上传-取消分段上传任务(go sdk)
更新时间:2024-06-21 gmt 08:00

分段上传-九游平台

功能说明

通过分段上传任务的id,取消指定桶中的分段上传任务。

您可以选择取消多段上传任务,取消多段上传任务之后无法再次使用该上传id上传任何段。然后,obs将释放被取消的多段上传任务中的每个段数据的所有存储。如果有多段上传已在进行中,即使您已执行中止操作,它们仍可以上传成功或失败。如果要释放所有分段使用的所有存储,必须在完成所有多段上传后再取消多段上传任务。

接口约束

  • 您必须是桶拥有者或拥有取消分段上传任务的权限,才能取消分段上传任务。建议使用iam或桶策略进行授权,如果使用iam则需授予obs:object:abortmultipartupload权限,如果使用桶策略则需授予abortmultipartupload权限。相关授权方式介绍可参见obs权限控制概述,配置方式详见、。
  • obs支持的region与endpoint的对应关系,详细信息请参见。

方法定义

func (obsclient obsclient) abortmultipartupload(input *abortmultipartuploadinput, extensions...extensionoptions) (output *basemodel, err error)

请求参数说明

表1 请求参数列表

参数名称

参数类型

是否必选

描述

input

*abortmultipartuploadinput

必选

参数解释:

取消分段上传任务请求参数。详情参见abortmultipartuploadinput

extensions

可选

参数解释:

拓展配置项。通过调用拓展配置项为对应请求配置额外的拓展请求头,详情参见。

表2 abortmultipartuploadinput

参数名称

参数类型

是否必选

描述

bucket

string

必选

参数解释

桶名。

约束限制:

  • 桶的名字需全局唯一,不能与已有的任何桶名称重复,包括其他用户创建的桶。
  • 桶命名规则如下:
    • 3~63个字符,数字或字母开头,支持小写字母、数字、“-”、“.”。
    • 禁止使用ip地址。
    • 禁止以“-”或“.”开头及结尾。
    • 禁止两个“.”相邻(如:“my..bucket”)。
    • 禁止“.”和“-”相邻(如:“my-.bucket”和“my.-bucket”)。
  • 同一用户在同一个区域多次创建同名桶不会报错,创建的桶属性以第一次请求为准。

默认取值:

key

string

必选

参数解释:

对象名。对象名是对象在存储桶中的唯一标识。对象名是对象在桶中的完整路径,路径中不包含桶名。

例如,您对象的访问地址为examplebucket.obs.cn-north-4.myhuaweicloud.com/folder/test.txt 中,对象名为folder/test.txt。

取值范围:

长度大于0且不超过1024的字符串。

默认取值:

uploadid

string

必选

参数解释:

分段上传任务的id,例如:000001648453845dbb78f2340dd460d8

取值范围:

长度为32的字符串。

默认取值:

返回结果说明

表3 返回结果

参数名称

参数类型

描述

output

*basemodel

参数解释:

接口返回信息。详情参见basemodel

err

error

参数解释:

接口返回错误信息。

表4 basemodel

参数名称

参数类型

描述

statuscode

int

参数解释:

http状态码。

取值范围:

状态码是一组从2xx(成功)到4xx或5xx(错误)的数字代码,状态码表示了请求响应的状态。完整的状态码列表请参见。

默认取值:

requestid

string

参数解释:

obs服务端返回的请求id。

默认取值:

responseheaders

map[string][]string

参数解释:

http响应头信息。

默认取值:

代码样例

本示例用于取消指定桶 examplebucket 中的分段上传任务,并且对象名是example/objectname,上传任务id是 0000000xxxxxxxx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
packagemain
import(
"fmt"
"os"
obs"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)
funcmain(){
//推荐通过环境变量获取aksk,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。
//您可以登录访问管理控制台获取访问密钥ak/sk,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。
ak:=os.getenv("accesskeyid")
sk:=os.getenv("secretaccesskey")
// 【可选】如果使用临时ak/sk和securitytoken访问obs,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥ak/sk,也可以使用其他外部引入方式传入。
// securitytoken := os.getenv("securitytoken")
// endpoint填写bucket对应的endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写。
endpoint:="https://obs.cn-north-4.myhuaweicloud.com"
// 创建obsclient实例
// 如果使用临时aksk和securitytoken访问obs,需要在创建实例时通过obs.withsecuritytoken方法指定securitytoken值。
obsclient,err:=obs.new(ak,sk,endpoint/*, obs.withsecuritytoken(securitytoken)*/)
iferr!=nil{
fmt.printf("create obsclient error, errmsg: %s",err.error())
}
input:=&obs.abortmultipartuploadinput{}
// 指定存储桶名称
input.bucket="examplebucket"
// 指定上传对象名,此处以 example/objectname 为例
input.key="example/objectname"
// 指定多段上传任务号,此处以00000188677110424014075cc4a77xxx为例
input.uploadid="00000188677110424014075cc4a77xxx"
// 取消分段上传任务
output,err:=obsclient.abortmultipartupload(input)
iferr==nil{
fmt.printf("abort multipart upload successful!\n")
fmt.printf("requestid:%s\n",output.requestid)
return
}
fmt.printf("abort multipart upload fail!\n")
ifobserror,ok:=err.(obs.obserror);ok{
fmt.println("an obserror was found, which means your request sent to obs was rejected with an error response.")
fmt.println(obserror.error())
}else{
fmt.println("an exception was found, which means the client encountered an internal problem when attempting to communicate with obs, for example, the client was unable to access the network.")
fmt.println(err)
}
}

相关链接

  • 关于分段上传-取消分段上传任务的api说明,请参见取消多段上传任务
  • 更多关于分段上传的示例代码,请参见。
  • 分段上传过程中返回的错误码含义、问题原因及处理措施可参考obs错误码

相关文档

网站地图