forked from aliyun/alibabacloud-oss-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostobject.tea
157 lines (148 loc) · 4.71 KB
/
postobject.tea
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Util;
import OSSUtil;
import FileForm;
import XML;
type @endpoint = string
type @regionId = string
type @protocol = string
type @userAgent = string
type @readTimeout = number
type @connectTimeout = number
type @httpProxy = string
type @httpsProxy = string
type @noProxy = string
type @maxIdleConns = number
type @hostModel = string
type @addtionalHeaders = [ string ]
model Config {
credentialType?: string,
securityToken?: string,
accessKeyId: string,
accessKeySecret: string,
endpoint: string,
protocol?: string,
regionId: string,
userAgent?: string,
hostModel?: string,
signatureVersion?: string,
isEnableMD5?: boolean,
isEnableCrc?: boolean,
readTimeout?: number,
connectTimeout?: number,
localAddr?: string,
httpProxy?: string,
httpsProxy?: string,
noProxy?: string,
socks5Proxy?: string,
socks5NetWork?: string,
maxIdleConns?: number,
addtionalHeaders?: [ string ],
}
init(config: Config){
if (Util.isUnset(config)) {
throw {
name = "ParameterMissing",
message = "'config' can not be unset"
};
}
if (Util.empty(config.endpoint)) {
throw {
name = "ParameterMissing",
message = "'config.endpoint' can not be empty"
};
}
if (Util.empty(config.regionId)) {
throw {
name = "ParameterMissing",
message = "'config.regionId' can not be empty"
};
}
@endpoint = config.endpoint;
@protocol = config.protocol;
@regionId = config.regionId;
@userAgent = config.userAgent;
@readTimeout = config.readTimeout;
@connectTimeout = config.connectTimeout;
@httpProxy = config.httpProxy;
@httpsProxy = config.httpsProxy;
@noProxy = config.noProxy;
@maxIdleConns = config.maxIdleConns;
@addtionalHeaders = config.addtionalHeaders;
}
model PostObjectRequest = {
bucketName: string(description='BucketName', name='BucketName', pattern='[a-zA-Z0-9-_]+'),
header: {
accessKeyId: string(description='OSSAccessKeyId', name='OSSAccessKeyId'),
policy: string(description='policy', name='policy'),
signature: string(description='Signature', name='Signature'),
successActionStatus?: string(description='success_action_status', name='success_action_status'),
file: FileForm.FileField,
key: string(description='key', name='key'),
userMeta?: map[string]string(description='UserMeta', name='UserMeta')
}(description='header', name='header')
}
model PostObjectResponse = {
postResponse: {
bucket: string(description='Bucket', name='Bucket'),
eTag: string(description='ETag', name='ETag'),
location: string(description='Location', name='Location'),
}(description='PostResponse', name='PostResponse'),
}
api postObject(request: PostObjectRequest, runtime: OSSUtil.RuntimeOptions): PostObjectResponse {
var boundary = FileForm.getBoundary();
__request.protocol = @protocol;
__request.method = 'POST';
__request.pathname = `/`;
__request.headers = {
host = OSSUtil.getHost(request.bucketName, @regionId, @endpoint, @hostModel),
date = Util.getDateUTCString(),
user-agent = getUserAgent(),
};
__request.headers.content-type = `multipart/form-data; boundary=${boundary}`;
var form = {
OSSAccessKeyId = request.header.accessKeyId,
policy = request.header.policy,
Signature = request.header.signature,
key = request.header.key,
success_action_status = request.header.successActionStatus,
file = request.header.file,
...OSSUtil.toMeta(request.header.userMeta, 'x-oss-meta-'),
};
__request.body = FileForm.toFileForm(form, boundary);
} returns {
var respMap : object = null;
var bodyStr = Util.readAsString(__response.body);
if (Util.is4xx(__response.statusCode) || Util.is5xx(__response.statusCode)) {
respMap = OSSUtil.getErrMessage(bodyStr);
throw {
code = respMap.Code,
message = respMap.Message,
data = {
httpCode = __response.statusCode,
requestId = respMap.RequestId,
hostId = respMap.HostId,
}
};
}
respMap = XML.parseXml(bodyStr, PostObjectResponse);
return {
...respMap,
};
} runtime {
timeouted = 'retry',
readTimeout = Util.defaultNumber(runtime.readTimeout, @readTimeout),
connectTimeout = Util.defaultNumber(runtime.connectTimeout, @connectTimeout),
httpProxy = Util.defaultString(runtime.httpProxy, @httpProxy),
httpsProxy = Util.defaultString(runtime.httpsProxy, @httpsProxy),
noProxy = Util.defaultString(runtime.noProxy, @noProxy),
maxIdleConns = Util.defaultNumber(runtime.maxIdleConns, @maxIdleConns),
retry = {
retryable = runtime.autoretry,
maxAttempts = Util.defaultNumber(runtime.maxAttempts, 3)
},
backoff = {
policy = Util.defaultString(runtime.backoffPolicy, 'no'),
period = Util.defaultNumber(runtime.backoffPeriod, 1)
},
ignoreSSL = runtime.ignoreSSL
}