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 #pragma once
18 #include "ResumableBaseWorker.h"
19 #include "../external/json/json.h"
20 
21 namespace AlibabaCloud
22 {
23 namespace OSS
24 {
25     struct UploadRecord{
26         std::string opType;
27         std::string uploadID;
28         std::string filePath;
29         std::string bucket;
30         std::string key;
31         std::string mtime;
32         uint64_t size;
33         uint64_t partSize;
34         std::string md5Sum;
35     };
36 
37     class ResumableUploader : public ResumableBaseWorker
38     {
39     public:
40         ResumableUploader(const UploadObjectRequest& request, const OssClientImpl *client);
41 
42         PutObjectOutcome Upload();
43 
44     protected:
45         virtual InitiateMultipartUploadOutcome InitiateMultipartUploadWrap(const InitiateMultipartUploadRequest &request) const;
46         virtual PutObjectOutcome UploadPartWrap(const UploadPartRequest &request) const;
47         virtual ListPartsOutcome ListPartsWrap(const ListPartsRequest &request) const;
48         virtual CompleteMultipartUploadOutcome CompleteMultipartUploadWrap(const CompleteMultipartUploadRequest &request) const;
49 
50         virtual void initRecordInfo();
51         virtual void buildRecordInfo(const AlibabaCloud::OSS::Json::Value& value);
52         virtual void dumpRecordInfo(AlibabaCloud::OSS::Json::Value& value);
53         virtual int validateRecord();
54 
55     private:
56         int getPartsToUpload(OssError &err, PartList &partsUploaded, PartList &partsToUpload);
57         virtual void genRecordPath();
58         virtual int loadRecord();
59         virtual int prepare(OssError& err);
60 
61         const UploadObjectRequest& request_;
62         UploadRecord record_;
63         const OssClientImpl *client_;
64         std::string uploadID_;
65         static void UploadPartProcessCallback(size_t increment, int64_t transfered, int64_t total, void *userData);
66     };
67 }
68 }
69