MongoDB C++ Driver mongocxx-3.10.1
Loading...
Searching...
No Matches
uploader.hpp
1// Copyright 2017 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
21#include <mongocxx/gridfs/bucket-fwd.hpp>
22#include <mongocxx/gridfs/uploader-fwd.hpp>
23
24#include <bsoncxx/document/value.hpp>
25#include <bsoncxx/stdx/optional.hpp>
26#include <bsoncxx/stdx/string_view.hpp>
27#include <bsoncxx/types/bson_value/view.hpp>
28#include <bsoncxx/view_or_value.hpp>
29#include <mongocxx/client_session.hpp>
30#include <mongocxx/collection.hpp>
31#include <mongocxx/result/gridfs/upload.hpp>
32#include <mongocxx/stdx.hpp>
33
34#include <mongocxx/config/prelude.hpp>
35
36namespace mongocxx {
37namespace v_noabi {
38namespace gridfs {
39
43class uploader {
44 public:
50 uploader() noexcept;
51
55 uploader(uploader&&) noexcept;
56
60 uploader& operator=(uploader&&) noexcept;
61
62 uploader(const uploader&) = delete;
63
64 uploader& operator=(const uploader&) = delete;
65
70
74 explicit operator bool() const noexcept;
75
94 void write(const std::uint8_t* bytes, std::size_t length);
95
108 result::gridfs::upload close();
109
118 void abort();
119
126 std::int32_t chunk_size() const;
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 MONGOCXX_PRIVATE uploader(
153 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 MONGOCXX_PRIVATE void finish_chunk();
162 MONGOCXX_PRIVATE void flush_chunks();
163
164 class MONGOCXX_PRIVATE impl;
165
166 MONGOCXX_PRIVATE impl& _get_impl();
167 MONGOCXX_PRIVATE 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)
178#include <mongocxx/config/postlude.hpp>
179#endif
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:47
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:86
Class representing a GridFS bucket.
Definition bucket.hpp:63
Class used to upload a GridFS file.
Definition uploader.hpp:43
void abort()
Aborts uploading the file.
uploader() noexcept
Default constructs an uploader object.
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.
The top-level namespace for bsoncxx library entities.
Definition element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition bulk_write-fwd.hpp:19