Skip to content

Commit

Permalink
Object metadata should be optional in resumable uploads #332
Browse files Browse the repository at this point in the history
added cpp examples
  • Loading branch information
martinzink committed Mar 1, 2022
1 parent cf3fcb0 commit 8b7b7b2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
19 changes: 19 additions & 0 deletions examples/cpp/CMakeLists.txt
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)
15 changes: 15 additions & 0 deletions examples/cpp/list_bucket.cpp
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();
}
}
20 changes: 20 additions & 0 deletions examples/cpp/upload.cpp
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";
}
}
3 changes: 0 additions & 3 deletions fakestorage/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,6 @@ func (s *Server) resumableUpload(bucketName string, r *http.Request) jsonRespons
predefinedACL := r.URL.Query().Get("predefinedAcl")
contentEncoding := r.URL.Query().Get("contentEncoding")
metadata, err := loadMetadata(r.Body)
if err != nil {
return jsonResponse{errorMessage: err.Error()}
}
objName := r.URL.Query().Get("name")
if objName == "" {
objName = metadata.Name
Expand Down

0 comments on commit 8b7b7b2

Please sign in to comment.