Store game-wide data in binary records
Overview
The AccelByte Gaming Services (AGS) Cloud Save service enables you to store your game data in binary format. The data that is stored is for global title uses that are accessible and, in some cases, editable by the players.
In this article, you will learn how to use binary records to store your player data, retrieve it, and modify it according to your game use case.
Goals
This article gives an overview of game binary records and how to use them with the AGS Game SDK, and shows you how to do the following:
- Store game data in binary records
- Retrieve game binary records
- Modify game binary records
- Delete game binary records
Prerequisites
To complete the steps in this article, you will need:
- Access to the AGS Admin Portal
- The AGS Game SDK for Unreal or Unity installed to your game project with the required permissions:
- Client ID
- Client Secret
Store game data in binary records with the game server
Storing game data in binary records can only be done by the game server, which can be set up by completing the steps in this section.
Create game binary record request
You will first need to create a binary record you wish to store. From this process, you will get the generated pre-signed URL that will be used later to upload the binary file. You can create the request by using the following function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FServerApiClientPtr ServerApiClient = FMultiRegistry::GetServerApiClient();
FString Key = "GameInformation1";
EAccelByteFileType FileType = EAccelByteFileType::BIN; // Valid file types are jpeg, jpg, png, bmp, gif, mp3, webp, and bin
ESetByMetadataRecord SetBy = ESetByMetadataRecord::CLIENT; // Set to client if you want the binary to be managed by the game client or using public endpoints
ServerApiClient->ServerBinaryCloudSave.CreateGameBinaryRecord(Key
, FileType
, SetBy
, THandler<FAccelByteModelsBinaryInfo>::CreateLambda([](FAccelByteModelsBinaryInfo Result)
{
// Do something if CreateGameBinaryRecord succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if CreateGameBinaryRecord fails
}));
ServerBinaryCloudSave serverBinaryCloudSave = AccelByteSDK.GetServerRegistry().GetApi().GetBinaryCloudSave();
string key = "GameInformation1";
FileType fileType = FileType.BIN;
RecordSetBy setBy = RecordSetBy.CLIENT;
serverBinaryCloudSave.CreateGameBinaryRecord(key, fileType, setBy, ttlConfig: null, result =>
{
if (result.IsError)
{
// Your logic to handle errors in CreateGameBinaryRecord
// ...
Debug.Log($"Error CreateGameBinaryRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Your logic to run after CreateGameBinaryRecord succeeds
});
adminGameBinaryRecordService := &cloudsave.AdminGameBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
fileType := "bin"
setBy := "SERVER"
body := &cloudsaveclientmodels.ModelsGameBinaryRecordCreate {
FileType: &fileType,
SetBy: &setBy,
}
namespace := "mygame"
input := &admin_game_binary_record.AdminPostGameBinaryRecordV1Params{
Body: body,
Namespace: namespace,
}
result, err := adminGameBinaryRecordService.AdminPostGameBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.admin_post_game_binary_record_v1(
body=cloudsave_models.ModelsGameBinaryRecordCreate()
.with_key("GameInformation1")
.with_set_by("CLIENT")
.with_file_type("bin")
)
if error:
exit(error)
AdminGameBinaryRecord adminGameBinaryRecordWrapper = new AdminGameBinaryRecord(sdk);
ModelsUploadBinaryRecordResponse response;
try {
ModelsGameBinaryRecordCreate reqBody = ModelsGameBinaryRecordCreate.builder()
.fileType("bin")
.setBy(ModelsGameBinaryRecordCreate.SetBy.CLIENT.toString())
.build();
response = adminGameBinaryRecordWrapper.adminPostGameBinaryRecordV1(AdminPostGameBinaryRecordV1.builder()
.namespace("<namespace>")
.body(reqBody)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
String presignedUrlToUpload = response.getUrl();
}
var response = sdk.Cloudsave.AdminGameBinaryRecord.AdminPostGameBinaryRecordV1Op
.Execute(new ModelsGameBinaryRecordCreate()
{
FileType = "bin",
SetBy = ModelsGameBinaryRecordCreateSetBy.CLIENT
}, sdk.Namespace);
if (response != null)
{
string presignedUrlToUpload = response.Url!;
}
Or create a temporary game binary record request
- Unreal
- Unity
FServerApiClientPtr ServerApiClient = FMultiRegistry::GetServerApiClient();
FString Key = "GameInformation1";
EAccelByteFileType FileType = EAccelByteFileType::BIN; // Valid file types are jpeg, jpg, png, bmp, gif, mp3, webp, and bin
ESetByMetadataRecord SetBy = ESetByMetadataRecord::CLIENT; // Set to client if you want the binary to be managed by the game client or using public endpoints
FTTLConfig TTLConfig{};
TTLConfig.Action = EAccelByteTTLConfigAction::DELETE_RECORD;
TTLConfig.Expires_At = FDateTime::UtcNow() + FTimespan(0, 0, 5); // Will delete this record in the next five seconds
ServerApiClient->ServerBinaryCloudSave.CreateGameBinaryRecord(Key
, FileType
, SetBy
, THandler<FAccelByteModelsBinaryInfo>::CreateLambda([](FAccelByteModelsBinaryInfo Result)
{
// Do something if CreateGameBinaryRecord succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if CreateGameBinaryRecord fails
})
, TTLConfig);
ServerBinaryCloudSave serverBinaryCloudSave = AccelByteSDK.GetServerRegistry().GetApi().GetBinaryCloudSave();
string key = "GameInformation1";
FileType fileType = FileType.BIN;
RecordSetBy setBy = RecordSetBy.CLIENT;
var ttlConfig = new TTLConfig()
{
Action = TTLConfigAction.Delete,
ExpiresAt = DateTime.Now.AddSeconds(5) // Will delete this record in the next five sceonds
};
serverBinaryCloudSave.CreateGameBinaryRecord(key, fileType, setBy, ttlConfig, result =>
{
if (result.IsError)
{
// Your logic to handle errors in CreateGameBinaryRecord
// ...
Debug.Log($"Error CreateGameBinaryRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Your logic to run after CreateGameBinaryRecord succeeds
});
Upload binary file
Upload the binary file directly with the pre-signed URL you have. You can use the following function to upload the binary file:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FString Url = "PresignedUrlToUpload";
TArray<uint8> DataUpload = { 106, 35, 171, 106, 138, 197, 77, 94, 182, 18, 99, 9, 245, 110, 45, 197, 22, 35 };
FAccelByteNetUtilities::UploadTo(Url
, DataUpload
, FHttpRequestProgressDelegate::CreateLambda([](const FHttpRequestPtr& Request, int32 BytesSent, int32 BytesReceived)
{
// Do something if UploadTo still in progress successful
})
, FVoidHandler::CreateLambda([]()
{
// Do something if UploadTo succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UploadTo fails
}));
string url = "PresignedUrlToUpload";
byte[] dataUpload = new byte[] { 106, 35, 171, 106, 138, 197, 77, 94, 182, 18, 99, 9, 245, 110, 45, 197, 22, 35 }
AccelByteNetUtilities.UploadBinaryTo(url, dataUpload, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UploadBinaryTo
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UploadBinaryTo succeeds
});
presignedURL := "PresignedUrlToUpload"
filePath := "FilePath"
resp, err := utils.UploadBinaryFile(presignedURL, token, filePath)
if err != nil {
// Do something if an error occurs
}
from accelbyte_py_sdk.core import get_http_client
# data_upload = ...
url = "PresignedUrlToUpload"
response = get_http_client().post(
url=url,
data=data_upload,
headers={
"Content-Type": "application/octet-stream",
}
)
String presignedUrlToUpload = "<url>"; // From AdminPostGameBinaryRecordV1
byte[] dataToUpload = new byte[] { 10, 30, 40, 50, 60, 70, 80 };
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(presignedUrlToUpload))
.PUT(HttpRequest.BodyPublishers.ofByteArray(dataToUpload))
.header("Content-Type", "application/octet-stream")
.build();
HttpResponse<String> httpResponse;
try {
httpResponse =
client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (httpResponse.statusCode() >= HttpURLConnection.HTTP_OK && httpResponse.statusCode() < HttpURLConnection.HTTP_MULT_CHOICE)
{
// Do something if upload succeeds
}
string presignedUrlToUpload = "<url>"; // From AdminPostGameBinaryRecordV1
byte[] dataToUpload = new byte[] { 10, 30, 40, 50, 60, 70, 80 };
HttpRequestMessage request = new HttpRequestMessage();
request.Method = HttpMethod.Put;
request.RequestUri = new Uri(presignedUrlToUpload);
request.Content = new StreamContent(new MemoryStream(dataToUpload));
request.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream");
var response = DefaultHttpClient.Http.Send(request);
if (response.IsSuccessStatusCode)
{
// Do something if upload succeeds
}
Commit to update the file location
Once the binary file is uploaded, commit the changes to make sure the new file location is updated by using the following function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FServerApiClientPtr ServerApiClient = FMultiRegistry::GetServerApiClient();
FString Key = "GameInformation1";
EAccelByteFileType FileType = EAccelByteFileType::BIN; // Valid file types are jpeg, jpg, png, bmp, gif, mp3, webp, and bin
FString FileLocation = "PresignUrlFileLocation";
ServerApiClient->ServerBinaryCloudSave.UpdateGameBinaryRecord(Key
, FileType
, FileLocation
, THandler<FAccelByteModelsGameBinaryRecord>::CreateLambda([](FAccelByteModelsGameBinaryRecord Result)
{
// What to do if UpdateGameBinaryRecord succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if UpdateGameBinaryRecord fails
}));
ServerBinaryCloudSave serverBinaryCloudSave = AccelByteSDK.GetServerRegistry().GetApi().GetBinaryCloudSave();
string key = "GameInformation1";
FileType fileType = FileType.BIN;
string fileLocation = "PresignUrlFileLocation";
serverBinaryCloudSave.UpdateGameBinaryRecord(key, fileType, fileLocation, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateGameBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UpdateGameBinaryRecord succeeds
})
adminGameBinaryRecordService := &cloudsave.AdminGameBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
contentType := "application/octet-stream"
fileLocation := "presignedUrlToUpload"
body := &cloudsaveclientmodels.ModelsBinaryRecordRequest {
ContentType: &contentType,
FileLocation: &fileLocation,
}
key := "someKey"
namespace := "mygame"
input := &admin_game_binary_record.AdminPutGameBinaryRecordV1Params{
Body: body,
Key: key,
Namespace: namespace,
}
result, err := adminGameBinaryRecordService.AdminPutGameBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.admin_put_game_binary_record_v1(
body=cloudsave_models.ModelsBinaryRecordRequest()
.with_content_type("bin")
.with_file_location("PresignUrlFileLocation"),
key="GameInformation1",
)
if error:
exit(error)
AdminGameBinaryRecord adminGameBinaryRecordWrapper = new AdminGameBinaryRecord(sdk);
String key = "someKey";
String presignedUrlToUpload = "<url>";
ModelsGameBinaryRecordAdminResponse response;
try {
ModelsBinaryRecordRequest reqBody = ModelsBinaryRecordRequest.builder()
.contentType("application/octet-stream")
.fileLocation(presignedUrlToUpload)
.build();
response = adminGameBinaryRecordWrapper.adminPutGameBinaryRecordV1(AdminPutGameBinaryRecordV1.builder()
.namespace("<namespace>")
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
// Do something if successful
}
string key = "someKey";
string presignedUrlToUpload = "<url>";
var response = sdk.Cloudsave.AdminGameBinaryRecord.AdminPutGameBinaryRecordV1Op
.Execute(new ModelsBinaryRecordRequest()
{
ContentType = "application/octet-stream",
FileLocation = presignedUrlToUpload
}, key, sdk.Namespace);
if (response != null)
{
// Do something if successful
}
Update a game binary record file from the game server
Updating a new binary file in a game binary record has slightly different steps compared to the game binary record creation. Complete the steps in this section to upload a new binary file from the game client.
Request a pre-signed URL
You will first need to request a pre-signed URL that you will use to upload the updated binary file. You can use the following function to request one:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FServerApiClientPtr ServerApiClient = FMultiRegistry::GetServerApiClient();
FString Key = "GameInformation1";
EAccelByteFileType FileType = EAccelByteFileType::BIN; // Valid file types are jpeg, jpg, png, bmp, gif, mp3, webp, and bin
ServerApiClient->ServerBinaryCloudSave.RequestGameBinaryRecordPresignedUrl(Key
, FileType
, THandler<FAccelByteModelsBinaryInfo>::CreateLambda([](FAccelByteModelsBinaryInfo Result)
{
// What to do if RequestGameBinaryRecordPresignedUrl succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if RequestGameBinaryRecordPresignedUrl fails
}));
ServerBinaryCloudSave serverBinaryCloudSave = AccelByteSDK.GetServerRegistry().GetApi().GetBinaryCloudSave();
string key = "GameInformation1";
FileType fileType = FileType.BIN;
serverBinaryCloudSave.RequestGameBinaryRecordPresignedUrl(key, fileType, result =>
{
if (result.IsError)
{
// Your logic to handle errors in RequestGameBinaryRecordPresignedUrl
// ...
Debug.Log($"Error RequestGameBinaryRecordPresignedUrl, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Your logic to run after RequestGameBinaryRecordPresignedUrl succeeds
});
adminGameBinaryRecordService := &cloudsave.AdminGameBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
fileType := "bin"
body := &cloudsaveclientmodels.ModelsUploadBinaryRecordRequest {
FileType: &fileType,
}
key := "someKey"
namespace := "mygame"
input := &admin_game_binary_record.AdminPostGameBinaryPresignedURLV1Params{
Body: body,
Key: key,
Namespace: namespace,
}
result, err := adminGameBinaryRecordService.AdminPostGameBinaryPresignedURLV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.admin_post_game_binary_presigned_urlv1(
body=cloudsave_models.ModelsUploadBinaryRecordRequest()
.with_file_type("bin"),
key="GameInformation1",
)
if error:
exit(error)
AdminGameBinaryRecord adminGameBinaryRecordWrapper = new AdminGameBinaryRecord(sdk);
String key = "someKey";
ModelsUploadBinaryRecordResponse response;
try {
ModelsUploadBinaryRecordRequest reqBody = ModelsUploadBinaryRecordRequest.builder()
.fileType("bin")
.build();
response = adminGameBinaryRecordWrapper.adminPostGameBinaryPresignedURLV1(AdminPostGameBinaryPresignedURLV1.builder()
.namespace("<namespace>")
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
String presignedUrlToUpload = response.getUrl();
}
string key = "someKey";
var response = sdk.Cloudsave.AdminGameBinaryRecord.AdminPostGameBinaryPresignedURLV1Op
.Execute(new ModelsUploadBinaryRecordRequest()
{
FileType = "bin"
}, key, sdk.Namespace);
if (response != null)
{
string presignedUrlToUpload = response.Url!;
}
Upload new binary file
Upload the binary file directly with the pre-signed URL you have. You can use the following function to upload the binary file:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FString Url = "PresignedUrlToUpload";
TArray<uint8> DataUpload = { 106, 35, 171, 106, 138, 197, 77, 94, 182, 18, 99, 9, 245, 110, 45, 197, 22, 35 };
FAccelByteNetUtilities::UploadTo(Url
, DataUpload
, FHttpRequestProgressDelegate::CreateLambda([](const FHttpRequestPtr& Request, int32 BytesSent, int32 BytesReceived)
{
// Do something if UploadTo still in progress successful
})
, FVoidHandler::CreateLambda([]()
{
// Do something if UploadTo succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UploadTo fails
}));
string url = "PresignedUrlToUpload";
byte[] dataUpload = new byte[] { 106, 35, 171, 106, 138, 197, 77, 94, 182, 18, 99, 9, 245, 110, 45, 197, 22, 35 }
AccelByteNetUtilities.UploadBinaryTo(url, dataUpload, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UploadBinaryTo
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UploadBinaryTo succeeds
});
presignedURL := "PresignedUrlToUpload"
filePath := "FilePath"
resp, err := utils.UploadBinaryFile(presignedURL, token, filePath)
if err != nil {
// Do something if an error occurs
}
from accelbyte_py_sdk.core import get_http_client
# data_upload = ...
url = "PresignedUrlToUpload"
response = get_http_client().post(
url=url,
data=data_upload,
headers={
"Content-Type": "application/octet-stream",
}
)
String presignedUrlToUpload = "<url>"; // From AdminPostGameBinaryPresignedURLV1
byte[] dataToUpload = new byte[] { 80, 30, 40, 50, 60, 70, 80 };
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(presignedUrlToUpload))
.PUT(HttpRequest.BodyPublishers.ofByteArray(dataToUpload))
.header("Content-Type", "application/octet-stream")
.build();
HttpResponse<String> httpResponse;
try {
httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (Exception e) {
// Do something when an error occurs
return;
}
if (httpResponse.statusCode() >= HttpURLConnection.HTTP_OK && httpResponse.statusCode() < HttpURLConnection.HTTP_MULT_CHOICE)
{
// Do something if upload succeeds
}
string presignedUrlToUpload = "<url>"; // From AdminPostGameBinaryPresignedURLV1Op
byte[] dataToUpload = new byte[] { 80, 30, 40, 50, 60, 70, 80 };
HttpRequestMessage request = new HttpRequestMessage();
request.Method = HttpMethod.Put;
request.RequestUri = new Uri(presignedUrlToUpload);
request.Content = new StreamContent(new MemoryStream(dataToUpload));
request.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream");
var response = DefaultHttpClient.Http.Send(request);
if (response.IsSuccessStatusCode)
{
// Do something if upload succeeds
}
Commit to update the file location again
Once the binary file is uploaded, commit the changes to make sure the new file location is updated using the following function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FServerApiClientPtr ServerApiClient = FMultiRegistry::GetServerApiClient();
FString Key = "GameInformation1";
EAccelByteFileType FileType = EAccelByteFileType::BIN; // Valid file types are jpeg, jpg, png, bmp, gif, mp3, webp, and bin
FString FileLocation = "PresignUrlFileLocation";
ServerApiClient->ServerBinaryCloudSave.UpdateGameBinaryRecord(Key
, FileType
, FileLocation
, THandler<FAccelByteModelsGameBinaryRecord>::CreateLambda([](FAccelByteModelsGameBinaryRecord Result)
{
// What to do if UpdateGameBinaryRecord succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if UpdateGameBinaryRecord fails
}));
ServerBinaryCloudSave serverBinaryCloudSave = AccelByteSDK.GetServerRegistry().GetApi().GetBinaryCloudSave();
string key = "GameInformation1";
FileType fileType = FileType.BIN;
string fileLocation = "PresignUrlFileLocation";
serverBinaryCloudSave.UpdateGameBinaryRecord(key, fileType, fileLocation, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateGameBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UpdateGameBinaryRecord succeeds
})
adminGameBinaryRecordService := &cloudsave.AdminGameBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
contentType := "application/octet-stream"
fileLocation := "presignedUrlToUpload"
body := &cloudsaveclientmodels.ModelsBinaryRecordRequest {
ContentType: &contentType,
FileLocation: &fileLocation,
}
key := "someKey"
namespace := "mygame"
input := &admin_game_binary_record.AdminPutGameBinaryRecordV1Params{
Body: body,
Key: key,
Namespace: namespace,
}
result, err := adminGameBinaryRecordService.AdminPutGameBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.admin_put_game_binary_record_v1(
body=cloudsave_models.ModelsBinaryRecordRequest()
.with_content_type("bin")
.with_file_location("PresignUrlFileLocation"),
key="GameInformation1",
)
if error:
exit(error)
AdminGameBinaryRecord adminGameBinaryRecordWrapper = new AdminGameBinaryRecord(sdk);
String key = "someKey";
String presignedUrlToUpload = "<url>";
ModelsGameBinaryRecordAdminResponse response;
try {
ModelsBinaryRecordRequest reqBody = ModelsBinaryRecordRequest.builder()
.contentType("application/octet-stream")
.fileLocation(presignedUrlToUpload)
.build();
response = adminGameBinaryRecordWrapper.adminPutGameBinaryRecordV1(AdminPutGameBinaryRecordV1.builder()
.namespace("<namespace>")
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
// Do something if successful
}
string key = "someKey";
string presignedUrlToUpload = "<url>";
var response = sdk.Cloudsave.AdminGameBinaryRecord.AdminPutGameBinaryRecordV1Op
.Execute(new ModelsBinaryRecordRequest()
{
ContentType = "application/octet-stream",
FileLocation = presignedUrlToUpload
}, key, sdk.Namespace);
if (response != null)
{
// Do something if successful
}
Delete game binary records from the game server
Use the following function to delete the game binary record:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FServerApiClientPtr ServerApiClient = FMultiRegistry::GetServerApiClient();
FString Key = "GameInformation1";
ServerApiClient->ServerBinaryCloudSave.DeleteGameBinaryRecord(Key
, FVoidHandler::CreateLambda([]()
{
// What to do if DeleteGameBinaryRecord succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if DeleteGameBinaryRecord fails
}));
ServerBinaryCloudSave serverBinaryCloudSave = AccelByteSDK.GetServerRegistry().GetApi().GetBinaryCloudSave();
string key = "GameInformation1";
serverBinaryCloudSave.DeleteGameBinaryRecord(key, result =>
{
if (result.IsError)
{
// Your logic to handle errors in DeleteGameBinaryRecord
// ...
Debug.Log($"Error DeleteGameBinaryRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Your logic to run after DeleteGameBinaryRecord succeeds
});
adminGameBinaryRecordService := &cloudsave.AdminGameBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
namespace := "mygame"
input := &admin_game_binary_record.AdminDeleteGameBinaryRecordV1Params{
Key: key,
Namespace: namespace,
}
err := adminGameBinaryRecordService.AdminDeleteGameBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.admin_delete_game_binary_record_v1(
key="GameInformation1",
)
if error:
exit(error)
final AdminGameBinaryRecord adminGameBinaryRecordWrapper = new AdminGameBinaryRecord(sdk);
String key = "someKey";
try {
adminGameBinaryRecordWrapper.adminDeleteGameBinaryRecordV1(AdminDeleteGameBinaryRecordV1.builder()
.namespace("<namespace>")
.key(key)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
string key = "someKey";
sdk.Cloudsave.AdminGameBinaryRecord.AdminDeleteGameBinaryRecordV1Op
.Execute(key, sdk.Namespace);
Retrieve game binary record data from the game client
After the game binary record data is stored, you can allow your player to retrieve that data.
Get single record
Use the following function to retrieve a specific game binary record data by key:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString Key = "GameInformation1";
ApiClient->BinaryCloudSave.GetGameBinaryRecord(Key
, THandler<FAccelByteModelsGameBinaryRecord>::CreateLambda([](FAccelByteModelsGameBinaryRecord Result)
{
// What to do if GetGameBinaryRecord succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if GetGameBinaryRecord fails
}));
BinaryCloudSave binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "GameInformation1";
binaryCloudSave.GetGameBinaryRecord(key, result =>
{
if (result.IsError)
{
// Your logic to handle errors in GetGameBinaryRecord
// ...
Debug.Log($"Error GetGameBinaryRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Your logic to run after GetGameBinaryRecord succeeds
});
publicGameBinaryRecordService := &cloudsave.PublicGameBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "somekey"
namespace := "mygame"
input := &public_game_binary_record.GetGameBinaryRecordV1Params{
Key: key,
Namespace: namespace,
}
result, err := publicGameBinaryRecordService.GetGameBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.get_game_binary_record_v1(
key="GameInformation1",
)
if error:
exit(error)
PublicGameBinaryRecord publicGameBinaryRecordWrapper = new PublicGameBinaryRecord(sdk);
String key = "someKey";
ModelsGameBinaryRecordResponse response;
try {
response = publicGameBinaryRecordWrapper.getGameBinaryRecordV1(GetGameBinaryRecordV1.builder()
.namespace("<namespace>")
.key(key)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
// Do something if successful
}
string key = "someKey";
var response = sdk.Cloudsave.PublicGameBinaryRecord.GetGameBinaryRecordV1Op
.Execute(key, sdk.Namespace);
if (response != null)
{
// Do something if successful
}
Get bulk records
Use the following function to get the list of game binary records:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
TArray<FString> Keys = { "GameInformation1", "GameInformation2" };
ApiClient->BinaryCloudSave.BulkGetGameBinaryRecords(Keys
, THandler<FAccelByteModelsListGameBinaryRecords>::CreateLambda([](FAccelByteModelsListGameBinaryRecords Result)
{
// What to do if BulkGetGameBinaryRecords succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if BulkGetGameBinaryRecords fails
}));
BinaryCloudSave binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string[] keys = { "GameInformation1", "GameInformation2" };
binaryCloudSave.BulkGetGameBinaryRecords(keys, result =>
{
if (result.IsError)
{
// Your logic to handle errors in BulkGetGameBinaryRecords
// ...
Debug.Log($"Error BulkGetGameBinaryRecords, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Your logic to run after BulkGetGameBinaryRecords succeeds
});
publicGameBinaryRecordService := &cloudsave.PublicGameBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
body := &cloudsaveclientmodels.ModelsBulkGetGameRecordRequest {
Keys: string[] {"key1", "key2"},
}
namespace := "mygame"
input := &public_game_binary_record.BulkGetGameBinaryRecordV1Params{
Body: body,
Namespace: namespace,
}
result, err := publicGameBinaryRecordService.BulkGetGameBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.bulk_get_game_binary_record_v1(
body=ModelsBulkGetGameRecordRequest().with_keys(["GameInformation1", "GameInformation2"]),
)
if error:
exit(error)
PublicGameBinaryRecord publicGameBinaryRecordWrapper = new PublicGameBinaryRecord(sdk);
List<String> keys = Arrays.asList("key1", "key2");
ModelsBulkGetGameBinaryRecordResponse response;
try {
ModelsBulkGetGameRecordRequest reqBody = ModelsBulkGetGameRecordRequest.builder()
.keys(keys)
.build();
response = publicGameBinaryRecordWrapper.bulkGetGameBinaryRecordV1(BulkGetGameBinaryRecordV1.builder()
.namespace("<namespace>")
.body(reqBody)
.build());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (response == null) {
// Null response from server
} else {
// Do something if successful
}
string[] keys = new[] { "key1", "key2" };
var response = sdk.Cloudsave.PublicGameBinaryRecord.BulkGetGameBinaryRecordV1Op
.Execute(new ModelsBulkGetGameRecordRequest()
{
Keys = new List<string>(keys)
}, sdk.Namespace);
if (response != null)
{
// Do something if successful
}
Download binary file
Download the binary file directly with the pre-signed URL you have. You can use the following function to download the binary file:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FString Url = "PresignedUrlToDownload";
FAccelByteNetUtilities::DownloadFrom(Url
, FHttpRequestProgressDelegate::CreateLambda([](const FHttpRequestPtr& Request, int32 BytesSent, int32 BytesReceived)
{
// Do something if DownloadFrom still in progress successful
})
, THandler<TArray<uint8>>::CreateLambda([&](const TArray<uint8>& RawData)
{
// Do something if DownloadFrom succeeds
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DownloadFrom fails
}));
string url = "PresignedUrlToDownload";
AccelByteNetUtilities.DownloadBinaryFrom(url, result =>
{
if (result.IsError)
{
// Your logic to handle errors in DownloadBinaryFrom
// ...
Debug.Log($"Error DownloadBinaryFrom, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Your logic to run after DownloadBinaryFrom succeeds
});
presignedURL := "PresignedUrlToDownload"
filePath := "FilePath"
resp, err := utils.DownloadBinary(presignedURL, token, filePath)
if err != nil {
// Do something if an error occurs
}
from accelbyte_py_sdk.core import get_http_client
http_client =
response = get_http_client().get(url="PresignedUrlToDownload")
String presignedUrlToUpload = "<url>";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(presignedUrlToUpload))
.build();
HttpResponse<String> httpResponse;
try {
httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (Exception e) {
// Do something if an error occurs
return;
}
if (httpResponse.statusCode() >= HttpURLConnection.HTTP_OK && httpResponse.statusCode() < HttpURLConnection.HTTP_MULT_CHOICE) {
// Do something with the response data if download succeeds
}
string presignedUrlToUpload = "<url>";
HttpRequestMessage request = new HttpRequestMessage();
request.RequestUri = new Uri(presignedUrlToUpload);
var response = DefaultHttpClient.Http.Send(request);
if (response.IsSuccessStatusCode)
{
// Do something with the response data if download succeeds
}