Appwrite C++ SDK
Auto-generated API documentation for the Appwrite C++ SDK
Loading...
Searching...
No Matches
Storage.hpp
Go to the documentation of this file.
1/// @file Storage.hpp
2/// @brief Manages file storage operations like upload, download, delete, and
3/// preview.
4#ifndef STORAGE_HPP
5#define STORAGE_HPP
6
7#include "Utils.hpp"
10#include <string>
11
12/**
13 * @class Storage
14 * @brief Provides methods to interact with Appwrite's Storage service.
15 *
16 * Enables management of buckets and files including creation, retrieval,
17 * update, and deletion.
18 */
19class Storage {
20 public:
21 /**
22 * @brief Constructs the Storage client with given project ID and API key.
23 * @param projectId The unique identifier of the Appwrite project.
24 * @param apiKey The secret API key for authentication.
25 */
26 Storage(const std::string &projectId, const std::string &apiKey);
27
28 /**
29 * @brief Lists all buckets in the project.
30 * @return JSON string containing the list of buckets.
31 */
32 std::string listBuckets();
33
34 /**
35 * @brief Retrieves metadata of a specific bucket.
36 * @param bucketId ID of the bucket to retrieve.
37 * @return JSON string containing bucket details.
38 */
39 std::string getBucket(std::string &bucketId);
40
41 /**
42 * @brief Creates a new storage bucket.
43 *
44 * @param bucketId Unique ID for the bucket.
45 * @param name Name of the bucket.
46 * @param permissions Optional permissions list.
47 * @param fileSecurity Flag for enabling file-level security.
48 * @param enabled Enables or disables the bucket.
49 * @param maximumFileSize Optional max file size limit.
50 * @param allowedFileExtensions Optional list of allowed file extensions.
51 * @param compression Compression type ("none", "gzip", etc.).
52 * @param encryption Enable server-side encryption.
53 * @param antivirus Enable antivirus scanning.
54 * @return JSON string with creation response.
55 */
56 std::string
57 createBucket(const std::string &bucketId, const std::string &name,
58 const std::vector<std::string> &permissions = {},
59 bool fileSecurity = false, bool enabled = true,
60 int maximumFileSize = 0,
61 const std::vector<std::string> &allowedFileExtensions = {},
62 const std::string &compression = "none",
63 bool encryption = false, bool antivirus = false);
64
65 /**
66 * @brief Updates an existing storage bucket.
67 *
68 * @param bucketId Unique ID of the bucket.
69 * @param name New name for the bucket.
70 * @param permissions Updated permissions list.
71 * @param fileSecurity Updated file-level security flag.
72 * @param enabled Whether the bucket is enabled.
73 * @param maximumFileSize Updated max file size limit.
74 * @param allowedFileExtensions Updated list of allowed extensions.
75 * @param compression Updated compression type.
76 * @param encryption Toggle encryption.
77 * @param antivirus Toggle antivirus.
78 * @return JSON string with update response.
79 */
80 std::string
81 updateBucket(const std::string &bucketId, const std::string &name,
82 const std::vector<std::string> &permissions = {},
83 bool fileSecurity = false, bool enabled = true,
84 int maximumFileSize = 0,
85 const std::vector<std::string> &allowedFileExtensions = {},
86 const std::string &compression = "none",
87 bool encryption = false, bool antivirus = false);
88
89 /**
90 * @brief Deletes a storage bucket.
91 * @param bucketId ID of the bucket to delete.
92 * @return JSON response string.
93 */
94 std::string deleteBucket(std::string &bucketId);
95
96 /**
97 * @brief Retrieves metadata of a specific file.
98 * @param bucketId Bucket ID where file is stored.
99 * @param fileId Unique file identifier.
100 * @return JSON string containing file metadata.
101 */
102 std::string getFile(const std::string &bucketId, const std::string &fileId);
103
104 /**
105 * @brief Returns a file preview URL.
106 * @param bucketId Bucket ID.
107 * @param fileId File ID.
108 * @return URL string for viewing the file.
109 */
110 std::string getFileView(const std::string &bucketId,
111 const std::string &fileId);
112
113 /**
114 * @brief Updates file metadata and permissions.
115 * @param bucketId Bucket ID.
116 * @param fileId File ID.
117 * @param name New name for the file (optional).
118 * @param permissions New permissions list.
119 * @return JSON response string.
120 */
121 std::string updateFile(const std::string &bucketId,
122 const std::string &fileId,
123 const std::string &name = "",
124 const std::vector<std::string> &permissions = {});
125
126 /**
127 * @brief Deletes a file from the bucket.
128 * @param bucketId Bucket ID.
129 * @param fileId File ID.
130 * @return JSON response string.
131 */
132 std::string deleteFile(const std::string &bucketId,
133 const std::string &fileId);
134
135 /**
136 * @brief Returns a downloadable URL for a file.
137 * @param bucketId Bucket ID.
138 * @param fileId File ID.
139 * @return URL string for downloading the file.
140 */
141 std::string getFileDownload(const std::string &bucketId,
142 const std::string &fileId);
143
144 /**
145 * @brief Uploads a file to the specified bucket.
146 * @param bucketId Target bucket ID.
147 * @param fileName Name to give the file.
148 * @param fileContent File content (base64 or raw).
149 * @param permissions Optional permissions list.
150 * @return JSON response string.
151 */
152 std::string createFile(const std::string &bucketId,
153 const std::string &fileName,
154 const std::string &fileContent,
155 const std::vector<std::string> &permissions);
156
157 private:
158 std::string apiKey; /**< The API key for accessing Appwrite. */
159 std::string projectId; /**< The Appwrite project identifier. */
160};
161
162#endif
Declares the base exception class used to represent Appwrite SDK errors.
Defines HTTP status code enums for consistent error and response handling.
Provides utility functions and helpers used across the SDK.
Provides methods to interact with Appwrite's Storage service.
Definition Storage.hpp:19
std::string updateFile(const std::string &bucketId, const std::string &fileId, const std::string &name="", const std::vector< std::string > &permissions={})
Updates file metadata and permissions.
std::string deleteFile(const std::string &bucketId, const std::string &fileId)
Deletes a file from the bucket.
Storage(const std::string &projectId, const std::string &apiKey)
Constructs the Storage client with given project ID and API key.
std::string updateBucket(const std::string &bucketId, const std::string &name, const std::vector< std::string > &permissions={}, bool fileSecurity=false, bool enabled=true, int maximumFileSize=0, const std::vector< std::string > &allowedFileExtensions={}, const std::string &compression="none", bool encryption=false, bool antivirus=false)
Updates an existing storage bucket.
std::string createFile(const std::string &bucketId, const std::string &fileName, const std::string &fileContent, const std::vector< std::string > &permissions)
Uploads a file to the specified bucket.
std::string deleteBucket(std::string &bucketId)
Deletes a storage bucket.
std::string getFileView(const std::string &bucketId, const std::string &fileId)
Returns a file preview URL.
std::string getFile(const std::string &bucketId, const std::string &fileId)
Retrieves metadata of a specific file.
std::string getBucket(std::string &bucketId)
Retrieves metadata of a specific bucket.
std::string getFileDownload(const std::string &bucketId, const std::string &fileId)
Returns a downloadable URL for a file.
std::string listBuckets()
Lists all buckets in the project.
std::string createBucket(const std::string &bucketId, const std::string &name, const std::vector< std::string > &permissions={}, bool fileSecurity=false, bool enabled=true, int maximumFileSize=0, const std::vector< std::string > &allowedFileExtensions={}, const std::string &compression="none", bool encryption=false, bool antivirus=false)
Creates a new storage bucket.