MongoDB C++ Driver mongocxx-3.11.0
Loading...
Searching...
No Matches
uploader.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
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// http://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#pragma once
16
17#include <cstddef>
18#include <cstdint>
19#include <memory>
20
23
29
33#include <mongocxx/stdx.hpp>
34
36
37namespace mongocxx {
38namespace v_noabi {
39namespace gridfs {
40
44class uploader {
45 public:
52
57
62
63 uploader(const uploader&) = delete;
64
65 uploader& operator=(const uploader&) = delete;
66
71
75 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
76
95 MONGOCXX_ABI_EXPORT_CDECL(void) write(const std::uint8_t* bytes, std::size_t length);
96
109 MONGOCXX_ABI_EXPORT_CDECL(result::gridfs::upload) close();
110
120
128
129 private:
130 friend ::mongocxx::v_noabi::gridfs::bucket;
131
132 //
133 // Constructs a new uploader stream.
134 //
135 // @param session
136 // The client session to use for upload operations.
137 //
138 // @param id
139 // The id of the GridFS file being uploaded.
140 //
141 // @param files
142 // The files collection of the bucket receiving the file.
143 //
144 // @param chunks
145 // The chunks collection of the bucket receiving the file.
146 //
147 // @param chunk_size
148 // The size in bytes of the chunks being uploaded.
149 //
150 // @param metadata
151 // Optional metadata field of the files collection document.
152 //
153 uploader(const client_session* session,
154 bsoncxx::v_noabi::types::bson_value::view id,
155 stdx::string_view filename,
156 collection files,
157 collection chunks,
158 std::int32_t chunk_size,
159 stdx::optional<bsoncxx::v_noabi::document::view_or_value> metadata = {});
160
161 void finish_chunk();
162 void flush_chunks();
163
164 class impl;
165
166 impl& _get_impl();
167 const impl& _get_impl() const;
168
169 std::unique_ptr<impl> _impl;
170};
171
172} // namespace gridfs
173} // namespace v_noabi
174} // namespace mongocxx
175
176// CXX-2770: missing include of postlude header.
177#if defined(MONGOCXX_TEST_MACRO_GUARDS_FIX_MISSING_POSTLUDE)
179#endif
180
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:48
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:87
Class representing a GridFS bucket.
Definition bucket.hpp:67
Class used to upload a GridFS file.
Definition uploader.hpp:44
void abort()
Aborts uploading the file.
void write(const std::uint8_t *bytes, std::size_t length)
Writes a specified number of bytes to a GridFS file.
std::int32_t chunk_size() const
Gets the chunk size of the file being uploaded.
result::gridfs::upload close()
Closes the uploader stream.
Provides mongocxx::v_noabi::client_session.
Provides mongocxx::v_noabi::collection.
Provides bsoncxx::v_noabi::document::value.
Declares mongocxx::v_noabi::gridfs::bucket.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:222
The mongocxx macro guard postlude header.
The mongocxx macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace within which all mongocxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::result::gridfs::upload.
Redeclares bsoncxx::v_noabi::stdx in mongocxx::v_noabi::stdx for internal use.
Provides std::string_view-related polyfills for library API usage.
Provides bsoncxx::v_noabi::types::bson_value::view.
Declares utilities to upload GridFS files.
Provides bsoncxx::v_noabi::view_or_value.