Store player data in binary records from game client
Overview
The AccelByte Gaming Services (AGS) Cloud Save service enables you to store your player data in binary format. The stored data will be tied to a specific player. Images and audio files are some of the common examples of data that are typically stored in player binary records.
In this guide, you will learn how to utilize binary records to store your player data, retrieve it, and modify it according to your game use case.
Prerequisites
You will need access to:
- The AGS Admin Portal
- The AGS Unreal, Unity, or Extend SDK, including the required permissions:
- Client ID
- Client Secret
- The AGS Cloud Save API documentation
Store player data in binary record from the Game Client
To store player data in binary records, follow these steps, in this order:
Create player binary record
In this process, you will get the generated pre pre-sign URL that will be used later to upload the binary file. You can also set the extra read validation to the record you want to create as follows:
- Allow only the record owner to access the data.
- Allow all player to access the record data.
For more details about extra read validation, see Introduction to Cloud Save.
To create a request, use this function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString Key = "userInformation";
FString FileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
bool bIsPublic = true; // Set to true if you want the binary to be public
ApiClient->BinaryCloudSave.SaveUserBinaryRecord(Key
, FileType
, bIsPublic
, FVoidHandler::CreateLambda([]()
{
// What to do if SaveUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if SaveUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string fileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
bool isPublic = true; // Set to true if you want the binary to be public
binaryCloudSave.SaveUserBinaryRecord(key, fileType, result =>
{
if (result.IsError)
{
// Your logic to handle errors in SaveUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after SaveUserBinaryRecord is successful
}, isPublic);
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
fileType := "bin"
isPublic := true
body := &cloudsaveclientmodels.ModelsPublicPlayerBinaryRecordCreate{
Key: &key,
FileType: &fileType,
IsPublic: isPublic,
}
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.PostPlayerBinaryRecordV1Params{
Body: body,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PostPlayerBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.post_player_binary_record_v1(
body=cloudsave_models.ModelsPublicPlayerBinaryRecordCreate()
.with_file_type("bin")
.with_key("userInformation")
.with_is_public(True),
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
ModelsUploadBinaryRecordResponse response;
try {
ModelsPublicPlayerBinaryRecordCreate reqBody = ModelsPublicPlayerBinaryRecordCreate.builder()
.key(key)
.fileType("bin")
.isPublic(true)
.build();
response = publicPlayerBinaryRecordWrapper.postPlayerBinaryRecordV1(PostPlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
String presignedUrlToUpload = response.getUrl();
}
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PostPlayerBinaryRecordV1Op
.Execute(new ModelsPublicPlayerBinaryRecordCreate()
{
Key = key,
FileType = "bin",
IsPublic = true
}, sdk.Namespace, userId);
if (response != null)
{
string presignedUrlToUpload = response.Url!;
}
Upload player binary record file
After creating the user binary record, you can now upload data to it. The needed parameters should be provided in the callbacks from the create player binary record section. You can upload data using this function:
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
byte[] yourUserDataToUpload; // Your user binary data
string url; // Retrieved via callback on successful SaveUserBinaryRecord (Value.BinaryInfo.Url)
AccelByteNetUtilities.UploadBinaryTo(binaryInfo.Url, yourUserDataToUpload, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UploadBinaryTo
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UploadBinaryTo is successful
});
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
# url = ...
# data_upload = ...
response = get_http_client().post(
url=url,
data=data_upload,
headers={
"Content-Type": "application/octet-stream",
}
)
String presignedUrlToUpload = "<url>"; //from PostPlayerBinaryRecordV1Op
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 when failed
return;
}
if (httpResponse.statusCode() >= HttpURLConnection.HTTP_OK && httpResponse.statusCode() >= HttpURLConnection.HTTP_MULT_CHOICE)
{
// Do something if upload succeeds
}
string presignedUrlToUpload = "<url>"; //from PostPlayerBinaryRecordV1Op
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 the changes
Once the binary file is uploaded, commit the changes to make sure the new file location is updated. Use this function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString Key = "userInformation";
FString ContentType = "presignUrlContentType";
FString FileLocation = "presignUrlFileLocation";
ApiClient->BinaryCloudSave.UpdateUserBinaryRecordFile(Key
, ContentType
, FileLocation
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if UpdateUserBinaryRecordFile is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if UpdateUserBinaryRecordFile fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string contentType; //Retrieved via callback on successful SaveUserBinaryRecord (Value.BinaryInfo.ContentType)
string fileLocation; //Retrieved via callback on successful SaveUserBinaryRecord (Value.BinaryInfo.FileLocation)
binaryCloudSave.UpdateUserBinaryRecordFile(key, contentType, fileLocation, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateUserBinaryRecordFile
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UpdateUserBinaryRecordFile is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
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"
userId := "myuserid"
input := &public_player_binary_record.PutPlayerBinaryRecordV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PutPlayerBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
# file_location = ... # from 'result.file_location' from 'post_player_binary_record_v1'
# content_type = ... # from 'result.content_type' from 'post_player_binary_record_v1'
result, error = cloudsave_service.put_player_binary_record_v1(
body=cloudsave_models.ModelsBinaryRecordRequest()
.with_content_type(content_type)
.with_file_location(file_location),
key="userInformation",
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
String presignedUrlToUpload = "<url>";
ModelsPlayerBinaryRecordResponse response;
try {
ModelsBinaryRecordRequest reqBody = ModelsBinaryRecordRequest.builder()
.contentType("application/octet-stream")
.fileLocation(presignedUrlToUpload)
.build();
response = publicPlayerBinaryRecordWrapper.putPlayerBinaryRecordV1(PutPlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
string userId = "<user-id>";
string key = "someKey";
string presignedUrlToUpload = "<url>";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PutPlayerBinaryRecordV1Op
.Execute(new ModelsBinaryRecordRequest()
{
ContentType = "application/octet-stream",
FileLocation = presignedUrlToUpload
}, key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
Retrieve player binary record data from the Game Client
You can retrieve two types of player records based on the record owner, which are as follows:
- Own player binary records.
- Other user's public binary records.
Retrieve a player's binary records data
Get Single
Use this function to retrieve a specific player's own 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 = "userInformation";
ApiClient->BinaryCloudSave.GetCurrentUserBinaryRecord(Key
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if GetCurrentUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if GetCurrentUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
binaryCloudSave.GetCurrentUserBinaryRecord(key, result =>
{
if (callback.IsError)
{
// Your logic to handle errors in GetCurrentUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after GetCurrentUserBinaryRecord is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.GetPlayerBinaryRecordV1Params{
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.GetPlayerBinaryRecordV1Short(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_player_binary_record_v1(
key="userInformation",
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
List<String> keys = Arrays.asList("key1", "key2");
ModelsBulkGetPlayerBinaryRecordResponse response;
try {
ModelsBulkGetPlayerRecordsRequest reqBody = ModelsBulkGetPlayerRecordsRequest.builder()
.keys(keys)
.build();
response = publicPlayerBinaryRecordWrapper.bulkGetMyBinaryRecordV1(BulkGetMyBinaryRecordV1.builder()
.namespace("<namespace>")
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.GetPlayerBinaryRecordV1Op
.Execute(key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
Bulk Get
Use this function to get list of binary records owned by the player.
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
TArray<FString> Keys = {"userInformation1", "userInformation2"};
ApiClient->BinaryCloudSave.BulkGetCurrentUserBinaryRecords(Keys
, THandler<FAccelByteModelsListUserBinaryRecords>::CreateLambda([](FAccelByteModelsListUserBinaryRecords Result)
{
// What to do if BulkGetCurrentUserBinaryRecords is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if BulkGetCurrentUserBinaryRecords fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string[] keys = new string[] {
"userInformation1",
"userInformation2"
};
binaryCloudSave.BulkGetCurrentUserBinaryRecords(keys, result =>
{
if (callback.IsError)
{
// Your logic to handle errors in BulkGetCurrentUserBinaryRecords
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after BulkGetCurrentUserBinaryRecords is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
body := &cloudsaveclientmodels.ModelsBulkGetPlayerRecordsRequest {
Keys: string[]{"key1", "key2"},
}
namespace := "mygame"
input := &public_player_binary_record.BulkGetMyBinaryRecordV1Params{
Body: body,
Namespace: namespace,
}
result, err := publicPlayerBinaryRecordService.BulkGetMyBinaryRecordV1Short(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_my_binary_record_v1(
body=cloudsave_models.ModelsBulkGetPlayerRecordsRequest().with_keys(["userInformation1", "userInformation2"]),
user_id="********************************",
)
if error:
exit(error)
string[] keys = new[] { "key1", "key2" };
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.BulkGetMyBinaryRecordV1Op
.Execute(new ModelsBulkGetPlayerRecordsRequest()
{
Keys = new List<string>(keys)
}, sdk.Namespace);
if (response != null)
{
// Do something when successful
}
Retrieve other user's public binary records data
Get Single
Use this function to retrieve a specific player public 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 = "userInformation";
FString UserId = "OtherPlayerUserId";
ApiClient->BinaryCloudSave.GetPublicUserBinaryRecord(Key
, UserId
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if GetPublicUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if GetPublicUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string userId = "otherPlayerUserId";
binaryCloudSave.GetPublicUserBinaryRecord(key, userId, result =>
{
if (result.IsError)
{
// Your logic to handle errors in GetPublicUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after GetPublicUserBinaryRecord is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.GetPlayerPublicBinaryRecordsV1Params{
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.GetPlayerPublicBinaryRecordsV1Short(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_player_public_binary_records_v1(
key="userInformation",
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
ModelsPlayerBinaryRecordResponse response;
try {
response = publicPlayerBinaryRecordWrapper.getPlayerPublicBinaryRecordsV1(GetPlayerPublicBinaryRecordsV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.GetPlayerPublicBinaryRecordsV1Op
.Execute(key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
Bulk Get
Use this function to get list of public binary records owned by other player.
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
TArray<FString> Keys = {"userInformation1", "userInformation2"};
FString UserId = "OtherPlayerUserId";
ApiClient->BinaryCloudSave.BulkGetPublicUserBinaryRecords(Keys
, UserId
, THandler<FAccelByteModelsListUserBinaryRecords>::CreateLambda([](FAccelByteModelsListUserBinaryRecords Result)
{
// What to do if BulkGetPublicUserBinaryRecords is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if BulkGetPublicUserBinaryRecords fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string[] keys = new string[] {
"userInformation1",
"userInformation2"
};
string userId = "otherPlayerUserId";
binaryCloudSave.BulkGetPublicUserBinaryRecords(keys, userId, result =>
{
if (result.IsError)
{
// Your logic to handle errors in BulkGetPublicUserBinaryRecords
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after BulkGetPublicUserBinaryRecords is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
body := &cloudsaveclientmodels.ModelsBulkGetPlayerRecordsRequest {
Keys: string[]{ "key1", "key2" },
}
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.BulkGetOtherPlayerPublicBinaryRecordsV1Params{
Body: body,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.BulkGetOtherPlayerPublicBinaryRecordsV1Short(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_other_player_public_binary_records_v1(
body=ModelsBulkGetPlayerRecordsRequest().with_keys(["userInformation1", "userInformation2"]),
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
List<String> keys = Arrays.asList("key1", "key2");
ModelsBulkGetPlayerBinaryRecordResponse response;
try {
ModelsBulkGetPlayerRecordsRequest reqBody = ModelsBulkGetPlayerRecordsRequest.builder()
.keys(keys)
.build();
response = publicPlayerBinaryRecordWrapper.bulkGetOtherPlayerPublicBinaryRecordsV1(BulkGetOtherPlayerPublicBinaryRecordsV1.builder()
.namespace("<namespace>")
.userId(userId)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
string userId = "<user-id>";
string[] keys = new[] { "key1", "key2" };
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.BulkGetOtherPlayerPublicBinaryRecordsV1Op
.Execute(new ModelsBulkGetPlayerRecordsRequest()
{
Keys = new List<string>(keys)
}, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
Modify player binary record from the Game Client
Player binary record data can be modified based on your game use case. You can modify player binary records data in two ways:
- Modify via a game client. Use this method if you want to allow your player to modify their player binary records data.
- Modify via a game server. Use this method if you only want the game server to be able to modify player binary records data.
For more detail about extra write validation, see Introduction to Cloud Save.
You can also let your players decide what information they want to update: record metadata or binary files.
Modify player binary record metadata
Use this function to only modify the records metadata.
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString Key = "userInformation";
FString FileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
bool bIsPublic = true; // Set to true if you want the binary to be public
ApiClient->BinaryCloudSave.SaveUserBinaryRecord(Key
, FileType
, bIsPublic
, FVoidHandler::CreateLambda([]()
{
// What to do if SaveUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if SaveUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
bool isPublic = true; // Set to true if you want the binary to be public
binaryCloudSave.UpdateUserBinaryRecordMetadata(key, isPublic, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateUserBinaryRecordMetadata
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UpdateUserBinaryRecordMetadata is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
body := &cloudsaveclientmodels.ModelsPlayerBinaryRecordMetadataPublicRequest {
IsPublic: true,
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.PutPlayerBinaryRecorMetadataV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PutPlayerBinaryRecorMetadataV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.post_player_binary_record_v1(
body=cloudsave_models.ModelsPublicPlayerBinaryRecordCreate()
.with_file_type("bin")
.with_key("userInformation")
.with_is_public(True),
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
ModelsPlayerBinaryRecordResponse response;
try {
ModelsPlayerBinaryRecordMetadataPublicRequest reqBody = ModelsPlayerBinaryRecordMetadataPublicRequest.builder()
.isPublic(true)
.build();
response = publicPlayerBinaryRecordWrapper.putPlayerBinaryRecorMetadataV1(PutPlayerBinaryRecorMetadataV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PutPlayerBinaryRecorMetadataV1Op
.Execute(new ModelsPlayerBinaryRecordMetadataPublicRequest()
{
IsPublic = true
}, key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
Upload new player binary record file
To upload a new player binary file in a player binary record from the Game Client, follow these steps, in this order:
Request pre-sign URL
You will need a pre-sign URL to upload the updated binary file in the Game Client. To request a pre-sign URL, use the following function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString Key = "userInformation";
FString FileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
ApiClient->BinaryCloudSave.RequestUserBinaryRecordPresignedUrl(Key
, FileType
, THandler<FAccelByteModelsBinaryInfo>::CreateLambda([](FAccelByteModelsBinaryInfo Result)
{
// What to do if RequestUserBinaryRecordPresignedUrl is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if RequestUserBinaryRecordPresignedUrl fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string fileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
binaryCloudSave.RequestUserBinaryRecordPresignedUrl(key, fileType, result =>
{
if (result.IsError)
{
// Your logic to handle errors in RequestUserBinaryRecordPresignedUrl
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after RequestUserBinaryRecordPresignedUrl is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
fileType := "bin"
body := &cloudsaveclientmodels.ModelsUploadBinaryRecordRequest {
FileType: &fileType,
}
namespace := "namespace"
userId := "myuserid"
input := &public_player_binary_record.PostPlayerBinaryPresignedURLV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PostPlayerBinaryPresignedURLV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.post_player_binary_presigned_urlv1(
body=cloudsave_models.ModelsUploadBinaryRecordRequest()
.with_file_type("bin")
key="userInformation",
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String key = "someKey";
String userId = "<user-id>";
ModelsUploadBinaryRecordResponse response;
try {
ModelsUploadBinaryRecordRequest reqBody = ModelsUploadBinaryRecordRequest.builder()
.fileType("bin")
.build();
response = publicPlayerBinaryRecordWrapper.postPlayerBinaryPresignedURLV1(PostPlayerBinaryPresignedURLV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
String presignedUrlToUpload = response.getUrl();
}
string key = "someKey";
string userId = "<user-id>";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PostPlayerBinaryPresignedURLV1Op
.Execute(new ModelsUploadBinaryRecordRequest()
{
FileType = "bin"
}, key, sdk.Namespace, userId);
if (response != null)
{
string presignedUrlToUpload = response.Url!;
}
Upload binary file
Once you have the needed parameter from the Request pre-sign URL section, upload your desired binary data or file. Use the following function:
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
byte[] yourUserDataToUpload; // Your user binary data
string url; // Retrieved via callback on successful RequestUserBinaryRecordPresignedUrl (Value.Url)
AccelByteNetUtilities.UploadBinaryTo(binaryInfo.Url, yourUserDataToUpload, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UploadBinaryTo
//...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UploadBinaryTo is successful
});
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
# url = ... # from 'result.url' from 'post_player_binary_presigned_urlv1'
# data_upload = ...
response = get_http_client().post(
url=url,
data=data_upload,
headers={
"Content-Type": "application/octet-stream",
}
)
String presignedUrlToUpload = "<url>"; //from PostPlayerBinaryPresignedURLV1
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 failed
return;
}
if (httpResponse.statusCode() >= HttpURLConnection.HTTP_OK && httpResponse.statusCode() >= HttpURLConnection.HTTP_MULT_CHOICE)
{
// Do something if upload succeeds
}
string presignedUrlToUpload = "<url>"; //from PostPlayerBinaryPresignedURLV1Op
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 the changes
Once the binary file is uploaded, commit the changes to make sure the new file location is updated. Use the following function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString Key = "userInformation";
// The following are taken from RequestUserBinaryRecordPresignedUrl's resulting FAccelByteModelsBinaryInfo
FString ContentType = RequestPresignedUrlResult.Content_Type;
FString FileLocation = RequestPresignedUrlResult.File_Location;
ApiClient->BinaryCloudSave.UpdateUserBinaryRecordFile(Key
, ContentType
, FileLocation
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if UpdateUserBinaryRecordFile is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if UpdateUserBinaryRecordFile fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string contentType; //Retrieved via callback on successful RequestUserBinaryRecordPresignedUrl (Value.ContentType)
string fileLocation; //Retrieved via callback on successful RequestUserBinaryRecordPresignedUrl (Value.FileLocation)
binaryCloudSave.UpdateUserBinaryRecordFile(key, contentType, fileLocation, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateUserBinaryRecordFile
// ...
return;
}
// Your logic to run after UpdateUserBinaryRecordFile is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
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"
userId := "myuserid"
input := &public_player_binary_record.PutPlayerBinaryRecordV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PutPlayerBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
# file_location = ... # from 'result.file_location' from 'post_player_binary_presigned_urlv1'
# content_type = ... # from 'result.content_type' from 'post_player_binary_presigned_urlv1'
result, error = cloudsave_service.put_player_binary_record_v1(
body=cloudsave_models.ModelsBinaryRecordRequest()
.with_content_type(content_type)
.with_file_location(file_location),
key="userInformation",
user_id="********************************",
)
if error:
exit(error)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
String presignedUrlToUpload = "<url>";
ModelsPlayerBinaryRecordResponse response;
try {
ModelsBinaryRecordRequest reqBody = ModelsBinaryRecordRequest.builder()
.contentType("application/octet-stream")
.fileLocation(presignedUrlToUpload)
.build();
response = publicPlayerBinaryRecordWrapper.putPlayerBinaryRecordV1(PutPlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
string userId = "<user-id>";
string key = "someKey";
string presignedUrlToUpload = "<url>";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PutPlayerBinaryRecordV1Op
.Execute(new ModelsBinaryRecordRequest()
{
ContentType = "application/octet-stream",
FileLocation = presignedUrlToUpload
}, key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
Delete player binary records from the Game Client
You can only allow your players to remove their own player binary records. To delete a player binary record, use the following function:
- Unreal
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString Key = "userInformation";
ApiClient->BinaryCloudSave.DeleteUserBinaryRecord(Key
, FVoidHandler::CreateLambda([]()
{
// What to do if DeleteUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if DeleteUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
binaryCloudSave.DeleteUserBinaryRecord(key, result =>
{
if (result.IsError)
{
// Your logic to handle errors in DeleteUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after DeleteUserBinaryRecord is successful
});
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.DeletePlayerBinaryRecordV1Params{
Key: key,
Namespace: namespace,
UserID: userId,
}
err := publicPlayerBinaryRecordService.DeletePlayerBinaryRecordV1Short(input)
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.delete_player_record_handler_v1(
key="userInformation",
user_id="********************************",
)
if error:
exit(error)
final PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
try {
publicPlayerBinaryRecordWrapper.deletePlayerBinaryRecordV1(DeletePlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
string userId = "<user-id>";
string key = "someKey";
sdk.Cloudsave.PublicPlayerBinaryRecord.DeletePlayerBinaryRecordV1Op
.Execute(key, sdk.Namespace, userId);