MongoDB C++ Driver mongocxx-3.7.0
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 <bsoncxx/document/value.hpp>
22#include <bsoncxx/stdx/optional.hpp>
23#include <bsoncxx/stdx/string_view.hpp>
24#include <bsoncxx/types/bson_value/view.hpp>
25#include <bsoncxx/view_or_value.hpp>
26#include <mongocxx/client_session.hpp>
27#include <mongocxx/collection.hpp>
28#include <mongocxx/result/gridfs/upload.hpp>
29#include <mongocxx/stdx.hpp>
30
31#include <mongocxx/config/prelude.hpp>
32
33namespace mongocxx {
34MONGOCXX_INLINE_NAMESPACE_BEGIN
35namespace gridfs {
36
40class MONGOCXX_API uploader {
41 public:
47 uploader() noexcept;
48
52 uploader(uploader&&) noexcept;
53
57 uploader& operator=(uploader&&) noexcept;
58
59 uploader(const uploader&) = delete;
60
61 uploader& operator=(const uploader&) = delete;
62
67
71 explicit operator bool() const noexcept;
72
91 void write(const std::uint8_t* bytes, std::size_t length);
92
105 result::gridfs::upload close();
106
115 void abort();
116
123 std::int32_t chunk_size() const;
124
125 private:
126 friend class bucket;
127
128 //
129 // Constructs a new uploader stream.
130 //
131 // @param session
132 // The client session to use for upload operations.
133 //
134 // @param id
135 // The id of the GridFS file being uploaded.
136 //
137 // @param files
138 // The files collection of the bucket receiving the file.
139 //
140 // @param chunks
141 // The chunks collection of the bucket receiving the file.
142 //
143 // @param chunk_size
144 // The size in bytes of the chunks being uploaded.
145 //
146 // @param metadata
147 // Optional metadata field of the files collection document.
148 //
149 MONGOCXX_PRIVATE uploader(const client_session* session,
150 bsoncxx::types::bson_value::view id,
151 stdx::string_view filename,
152 collection files,
153 collection chunks,
154 std::int32_t chunk_size,
155 stdx::optional<bsoncxx::document::view_or_value> metadata = {});
156
157 MONGOCXX_PRIVATE void finish_chunk();
158 MONGOCXX_PRIVATE void flush_chunks();
159
160 class MONGOCXX_PRIVATE impl;
161
162 MONGOCXX_PRIVATE impl& _get_impl();
163 MONGOCXX_PRIVATE const impl& _get_impl() const;
164
165 std::unique_ptr<impl> _impl;
166};
167
168} // namespace gridfs
169MONGOCXX_INLINE_NAMESPACE_END
170} // namespace mongocxx
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:40
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:83
Class representing a GridFS bucket.
Definition bucket.hpp:63
Class used to upload a GridFS file.
Definition uploader.hpp:40
uploader() noexcept
Default constructs an uploader object.
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
Top level namespace for the MongoDB C++ driver.
Definition bulk_write.hpp:24