Google Cloud Storage C++ Client  1.42.0
A C++ Client Library for Google Cloud Storage
upload_options.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_UPLOAD_OPTIONS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_UPLOAD_OPTIONS_H
17 
18 #include "google/cloud/storage/internal/complex_option.h"
19 #include "google/cloud/storage/version.h"
20 #include "google/cloud/storage/well_known_headers.h"
21 #include <string>
22 
23 namespace google {
24 namespace cloud {
25 namespace storage {
27 /**
28  * Request a resumable upload, restoring a previous session if necessary.
29  *
30  * When this option is used the client library prefers using resumable uploads.
31  *
32  * If the value passed to this option is the empty string, then the library will
33  * create a new resumable session. Otherwise the value should be the id of a
34  * previous upload session, the client library will restore that session in
35  * this case.
36  */
38  : public internal::ComplexOption<UseResumableUploadSession, std::string> {
39  using ComplexOption<UseResumableUploadSession, std::string>::ComplexOption;
40  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
41  // explicitly
43 
44  static char const* name() { return "resumable-upload"; }
45 };
46 
47 /// Create a UseResumableUploadSession option that restores previous sessions.
49  std::string session_id) {
50  return UseResumableUploadSession(std::move(session_id));
51 }
52 
53 /// Create a UseResumableUploadSession option that requests new sessions.
55  return UseResumableUploadSession("");
56 }
57 
58 /**
59  * Provide an expected final length of an uploaded object.
60  *
61  * Resumable uploads allow or an additional integrity check - make GCS check
62  * if the uploaded content matches the declared length. If it doesn't the upload
63  * will fail.
64  */
66  : public internal::WellKnownHeader<UploadContentLength, std::uintmax_t> {
67  using internal::WellKnownHeader<UploadContentLength,
68  std::uintmax_t>::WellKnownHeader;
69  static char const* header_name() { return "X-Upload-Content-Length"; }
70 };
71 
72 /**
73  * Upload the local file to GCS server starting at the given offset.
74  */
76  : public internal::ComplexOption<UploadFromOffset, std::uint64_t> {
77  using ComplexOption::ComplexOption;
78  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
79  // explicitly
80  UploadFromOffset() = default;
81  static char const* name() { return "upload-offset"; }
82 };
83 
84 /**
85  * The maximum length of the local file to upload to GCS server.
86  */
88  : public internal::ComplexOption<UploadLimit, std::uint64_t> {
89  using ComplexOption::ComplexOption;
90  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
91  // explicitly
92  UploadLimit() = default;
93  static char const* name() { return "upload-limit"; }
94 };
95 
96 /**
97  * Set the buffer size for a stream created in `Client::WriteObject()`.
98  *
99  * Some applications may need to tune the upload buffer for some specific
100  * uploads. This option can be passed to `Client::WriteObject()` to override the
101  * default setting in the `storage::Client`.
102  */
104  : public internal::ComplexOption<UploadBufferSize, std::size_t> {
105  using ComplexOption<UploadBufferSize, std::size_t>::ComplexOption;
106  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
107  // explicitly
108  UploadBufferSize() = default;
109  static char const* name() { return "upload-buffer-size"; }
110 };
111 
113 } // namespace storage
114 } // namespace cloud
115 } // namespace google
116 
117 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_UPLOAD_OPTIONS_H