-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Object metadata should be optional in resumable uploads #332
added cpp examples
- Loading branch information
1 parent
cf3fcb0
commit 8b7b7b2
Showing
4 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required (VERSION 3.2) | ||
set(CMAKE_CXX_STANDARD 20) | ||
project (fake-gcs-server-cpp-examples) | ||
include(FetchContent) | ||
|
||
set(GOOGLE_CLOUD_CPP_ENABLE storage CACHE INTERNAL storage-api) | ||
set(GOOGLE_CLOUD_CPP_ENABLE_MACOS_OPENSSL_CHECK OFF CACHE INTERNAL macos-openssl-check) | ||
set(BUILD_TESTING OFF CACHE INTERNAL testing-off) | ||
#TODO replace b03448411402c83082c279b246548d578dee05c7 with the next release which contains it | ||
FetchContent_Declare(google-cloud-cpp | ||
GIT_REPOSITORY [email protected]:googleapis/google-cloud-cpp.git | ||
GIT_TAG b03448411402c83082c279b246548d578dee05c7) | ||
FetchContent_MakeAvailable(google-cloud-cpp) | ||
|
||
add_executable(upload-example upload.cpp) | ||
target_link_libraries(upload-example google-cloud-cpp::storage) | ||
|
||
add_executable(list-bucket-example list_bucket.cpp) | ||
target_link_libraries(list-bucket-example google-cloud-cpp::storage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "google/cloud/storage/client.h" | ||
#include <iostream> | ||
|
||
using namespace google::cloud::storage; | ||
|
||
int main() { | ||
ClientOptions options(oauth2::CreateAnonymousCredentials()); | ||
options.set_endpoint("localhost:4443"); | ||
Client client(options, LimitedErrorCountRetryPolicy(2)); | ||
auto objects = client.ListObjects("my-bucket"); | ||
for (auto& object : objects) { | ||
if (object.ok()) | ||
std::cout << object.value(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "google/cloud/storage/client.h" | ||
#include <iostream> | ||
|
||
using namespace google::cloud::storage; | ||
|
||
int main() { | ||
ClientOptions options(oauth2::CreateAnonymousCredentials()); | ||
options.set_endpoint("localhost:4443"); | ||
Client client(options, LimitedErrorCountRetryPolicy(2)); | ||
client.CreateBucket("my-bucket", BucketMetadata()); | ||
auto writer = client.WriteObject("my-bucket", "my-key"); | ||
writer << "hello world"; | ||
writer.Close(); | ||
auto result = writer.metadata(); | ||
if (!result.ok()) { | ||
std::cout << "Upload failed: " << result.status().message(); | ||
} else { | ||
std::cout << "Upload succeeded"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters