MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
35
36namespace mongocxx {
37namespace v_noabi {
38namespace gridfs {
39
43class uploader {
44 public:
51
56
61
62 uploader(uploader const&) = delete;
63
64 uploader& operator=(uploader const&) = delete;
65
70
74 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
75
94 MONGOCXX_ABI_EXPORT_CDECL(void) write(std::uint8_t const* bytes, std::size_t length);
95
109
119
127
128 private:
129 friend ::mongocxx::v_noabi::gridfs::bucket;
130
131 //
132 // Constructs a new uploader stream.
133 //
134 // @param session
135 // The client session to use for upload operations.
136 //
137 // @param id
138 // The id of the GridFS file being uploaded.
139 //
140 // @param files
141 // The files collection of the bucket receiving the file.
142 //
143 // @param chunks
144 // The chunks collection of the bucket receiving the file.
145 //
146 // @param chunk_size
147 // The size in bytes of the chunks being uploaded.
148 //
149 // @param metadata
150 // Optional metadata field of the files collection document.
151 //
152 uploader(
153 client_session const* session,
154 bsoncxx::v_noabi::types::bson_value::view id,
155 bsoncxx::v_noabi::stdx::string_view filename,
156 collection files,
157 collection chunks,
158 std::int32_t chunk_size,
159 bsoncxx::v_noabi::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 impl const& _get_impl() const;
168
169 std::unique_ptr<impl> _impl;
170};
171
172} // namespace gridfs
173} // namespace v_noabi
174} // namespace mongocxx
175
177
uploader() noexcept
Default constructs an uploader object. The uploader is equivalent to the state of a moved from upload...
Supports MongoDB client session operations.
Definition client_session.hpp:50
A MongoDB collection.
Definition collection.hpp:87
A GridFS bucket.
Definition bucket.hpp:66
void abort()
Aborts uploading the file.
uploader() noexcept
Default constructs an uploader object. The uploader is equivalent to the state of a moved from upload...
std::int32_t chunk_size() const
Gets the chunk size of the file being uploaded.
void write(std::uint8_t const *bytes, std::size_t length)
Writes a specified number of bytes to a GridFS file.
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 export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities related to GridFS.
Declares entities representing the result of various commands.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v_noabi::result::gridfs::upload.
Provides bsoncxx::v_noabi::types::bson_value::view.
Declares utilities to upload GridFS files.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Provides bsoncxx::v_noabi::view_or_value.