Skip to main content
Version: 5.7.0

UploadFileFromMemory

Upload screenshots from memory instead of local file storage. On success the file will begin uploading to the brainCloud server.

This method allows uploads to happen in situations where local file access is not possible or convenient. For example, screenshots from Unity-based WebGL apps.

ServiceOperation
filePREPARE_USER_UPLOAD

Method Parameters

ParameterDescription
cloudPathThe desired cloud path of the file
cloudFilenameThe desired cloud fileName of the file
shareableTrue if the file is shareable
replaceIfExistsWhether to replace file if it exists
encodedTextThe converted file data from memory in string format

Usage

http://localhost:3000
// N/A
_bc.RegisterFileUploadCallbacks(FileCallbackSuccess, FileCallbackFail);

string cloudPath = "";
string cloudName = "image.png";
bool share = true;
bool overwrite = true;

int width = Screen.width;
int height = Screen.height;
var texture = new Texture2D(width, height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
texture.Apply();
byte[] bytes = texture.EncodeToPNG();

string encodedText = System.Convert.ToBase64String(bytes);

_bc.FileService.UploadFileFromMemory(
cloudPath,
cloudName,
share,
overwrite,
encodedText,
ApiSuccess, ApiError);
JSON Response
{
"status": 200,
"data": {
"fileDetails": {
"gameId": "12186",
"shareable": true,
"uploadId": "a11e0e65-8843-47a6-a1b7-c4e7a82baa88",
"replaceIfExists": true,
"cloudPath": "",
"expiresAt": 1605641010658,
"createdAt": 1605036210658,
"fileSize": 72636,
"profileId": "bc33dae0-9334-4798-9f4d-a5e99842e8c6",
"cloudLocation": "bc/g/12186/u/bc33dae0-9334-4798-9f4d-a5e99842e8c6/f/image.png",
"localPath": "iVBORw0KGgoAAAANSUhEUgAAAQ8AAAEFCAIAAABy...AElFTkSuQmCC",
"cloudFilename": "image.png",
"fileType": "User",
"updatedAt": 1605036210658
}
}
}