设置KV存储空间的单个大容量键值对,最大支持25M的值内容。
接口说明
本接口与 PutKv 的功能一样,只是允许上传更大请求体。当请求体较小时推荐直接使用 PutKv 接口,从而减少服务端处理时间。本接口需要使用 SDK 进行调用。以 golang SDK 为例,需要使用 PutKvWithHighCapacityAdvance 函数进行调用。
func TestPutKvWithHighCapacity() {
// 配置初始化
cfg := new(openapi.Config)
cfg.SetAccessKeyId("xxxxxxxxx")
cfg.SetAccessKeySecret("xxxxxxxxxx")
cli, err := NewClient(cfg)
if err != nil {
return err
}
runtime := &util.RuntimeOptions{}
// 构造待上传的键值对请求
namespace := "test-put-kv"
key := "test_PutKvWithHighCapacity_0"
value := strings.Repeat("t", 10*1024*1024)
rawReq := &PutKvRequest{
Namespace: &namespace,
Key: &key,
Value: &value,
}
payload, err := json.Marshal(rawReq)
if err != nil {
return err
}
// 如果 payload 大于 2M,则调用大容量接口进行上传
reqHighCapacity := &PutKvWithHighCapacityAdvanceRequest{
Namespace: &namespace,
Key: &key,
UrlObject: bytes.NewReader([]byte(payload)),
}
resp, err := cli.PutKvWithHighCapacityAdvance(reqHighCapacity, runtime)
if err != nil {
return err
}
return nil
}
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
调试
授权信息
请求参数
|
名称 |
类型 |
必填 |
描述 |
示例值 |
| Namespace |
string |
是 |
调用 CreateKvNamespace 时指定的名称。 |
test_namesapce |
| Key |
string |
是 |
需要设置的键名称,最长不超过 512 个字符,不能包含空格、反斜杠(/)。 |
test_key |
| Url |
string |
是 |
包含待设置键值对的 JSON 文件的公网可访问 HTTP(S) URL,服务端会主动下载该 URL 内容。
URL 指向的文件内容必须为如下 JSON 格式:{"Namespace":"<命名空间>","Key":" |
https://xxxobject.oss-cn-region.aliyuncs.com/9d91_xxxxxxxxxxx_158bb6e0f97c477791209bb46bd599f7 |
返回参数
|
名称 |
类型 |
描述 |
示例值 |
|
object |
Schema of Response |
||
| RequestId |
string |
请求 ID。 |
EEEBE525-F576-1196-8DAF-2D70CA3F4D2F |
| Length |
string |
键值对中的值的长度。 |
4 |
| Value |
string |
键的内容, 超过 256 个字符长度,将取前 100 及后 100 字符并省略中间。 |
test |
示例
正常返回示例
JSON格式
{
"RequestId": "EEEBE525-F576-1196-8DAF-2D70CA3F4D2F",
"Length": "4",
"Value": "test"
}
错误码
|
HTTP status code |
错误码 |
错误信息 |
描述 |
|---|---|---|---|
| 400 | InvalidAccount.Malformed | The specified account is invalid. | 账号输入不对,比如输入为空。 |
| 400 | InvalidNameSpace.Malformed | The specified namespace is invalid. | 存储空间名输入错误,比如输入空字符串。 |
| 400 | InvalidKey.Malformed | The specified key is invalid. | Key名输入错误,比如输入空字符串。 |
| 400 | InvalidKey.ExceedsMaximum | The size of the key cannot exceed 512 bytes. | 请求的Key的长度过大。 |
| 400 | InvalidValue.ExceedsMaximum | The size of the value cannot exceed 2,000,000 bytes. | 存入的值过大。 |
| 403 | InvalidKey.ExceedsCapacity | The maximum capacity of a single namespace cannot exceed 1 GB. | 存储空间的容量超过限制。 |
| 403 | Unauthorized.InvalidParameters | The specified authentication parameters are invalid. | 鉴权参数输入错误。 |
| 403 | Unauthorized.InvalidTime | The specified authentication time is invalid. | 您输入的鉴权时间参数无效,请检查参数值后重试。 |
| 403 | Unauthorized.InvalidToken | Token authentication failed. | 您输入的token无效,请检查并输入正确的token后进行重试。 |
| 404 | InvalidAccount.NotFound | The specified account does not exist. | 指定的账号不存在。 |
| 404 | InvalidNameSpace.NotFound | The specified namespace does not exist. | 指定的存储空间不存在。 |
| 404 | InvalidKey.NotFound | The specified key does not exist. | 指定的键值对不存在。 |
| 406 | InvalidNameSpace.Duplicate | The specified namespace already exists. | 指定的存储空间已经存在。 |
| 406 | InvalidNameSpace.QuotaFull | The maximum number of namespaces is exceeded. | 存储空间的个数超过容量限制。 |
| 429 | TooManyRequests | Too many requests are submitted. | 提交太频繁,请稍候再试 |
| 429 | TooQuickRequests | Request for putting or deleting keys are frequently submitted. | 键值对的修改或者删除操作太频繁。 |
访问错误中心查看更多错误码。
变更历史
更多信息,参考变更详情。