1 /*
2 * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <alibabacloud/oss/model/AppendObjectRequest.h>
19 #include <alibabacloud/oss/http/HttpType.h>
20 #include "utils/Utils.h"
21 using namespace AlibabaCloud::OSS;
22
AppendObjectRequest(const std::string & bucket,const std::string & key,const std::shared_ptr<std::iostream> & content)23 AppendObjectRequest::AppendObjectRequest(const std::string &bucket, const std::string &key,
24 const std::shared_ptr<std::iostream>& content):
25 OssObjectRequest(bucket, key),
26 position_(0),
27 content_(content)
28 {
29 }
30
AppendObjectRequest(const std::string & bucket,const std::string & key,const std::shared_ptr<std::iostream> & content,const ObjectMetaData & metaData)31 AppendObjectRequest::AppendObjectRequest(const std::string &bucket, const std::string &key,
32 const std::shared_ptr<std::iostream>& content, const ObjectMetaData &metaData):
33 OssObjectRequest(bucket, key),
34 position_(0),
35 content_(content),
36 metaData_(metaData)
37 {
38 }
39
setPosition(uint64_t position)40 void AppendObjectRequest::setPosition(uint64_t position)
41 {
42 position_ = position;
43 }
44
setCacheControl(const std::string & value)45 void AppendObjectRequest::setCacheControl(const std::string& value)
46 {
47 metaData_.addHeader(Http::CACHE_CONTROL, value);
48 }
49
setContentDisposition(const std::string & value)50 void AppendObjectRequest::setContentDisposition(const std::string& value)
51 {
52 metaData_.addHeader(Http::CONTENT_DISPOSITION, value);
53 }
54
setContentEncoding(const std::string & value)55 void AppendObjectRequest::setContentEncoding(const std::string& value)
56 {
57 metaData_.addHeader(Http::CONTENT_ENCODING, value);
58 }
59
setContentMd5(const std::string & value)60 void AppendObjectRequest::setContentMd5(const std::string& value)
61 {
62 metaData_.addHeader(Http::CONTENT_MD5, value);
63 }
64
setExpires(uint64_t expires)65 void AppendObjectRequest::setExpires(uint64_t expires)
66 {
67 metaData_.addHeader(Http::EXPIRES, std::to_string(expires));
68 }
69
setExpires(const std::string & value)70 void AppendObjectRequest::setExpires(const std::string& value)
71 {
72 metaData_.addHeader(Http::EXPIRES, value);
73 }
74
setAcl(const CannedAccessControlList & acl)75 void AppendObjectRequest::setAcl(const CannedAccessControlList& acl)
76 {
77 metaData_.addHeader("x-oss-object-acl", ToAclName(acl));
78 }
79
setTagging(const std::string & value)80 void AppendObjectRequest::setTagging(const std::string& value)
81 {
82 metaData_.addHeader("x-oss-tagging", value);
83 }
84
setTrafficLimit(uint64_t value)85 void AppendObjectRequest::setTrafficLimit(uint64_t value)
86 {
87 metaData_.addHeader("x-oss-traffic-limit", std::to_string(value));
88 }
89
Body() const90 std::shared_ptr<std::iostream> AppendObjectRequest::Body() const
91 {
92 return content_;
93 }
94
95
specialHeaders() const96 HeaderCollection AppendObjectRequest::specialHeaders() const
97 {
98 auto headers = metaData_.toHeaderCollection();
99
100 if (headers.find(Http::CONTENT_TYPE) == headers.end()) {
101 headers[Http::CONTENT_TYPE] = LookupMimeType(Key());
102 }
103
104 auto baseHeaders = OssObjectRequest::specialHeaders();
105 headers.insert(baseHeaders.begin(), baseHeaders.end());
106
107 return headers;
108 }
109
specialParameters() const110 ParameterCollection AppendObjectRequest::specialParameters() const
111 {
112 ParameterCollection paramters;
113 paramters["append"] = "";
114 paramters["position"] = std::to_string(position_);
115
116 return paramters;
117 }
118
119
120