PrepareUserUpload - CloudCode and JavaScript
Prepares a user file upload. On success an uploadId will be returned which can be used to upload the file using the _bc.file.uploadFile method.
Service | Operation |
---|---|
file | PREPARE_USER_UPLOAD |
Method Parameters
Parameter | Description |
---|---|
cloudPath | The desired cloud path of the file |
cloudFilename | The desired cloud fileName of the file |
shareable | True if the file is shareable |
replaceIfExists | Whether to replace file if it exists |
fileSize | The size of the file in bytes |
localPath | The path and fileName of the local file |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
// N/A
// N/A
// N/A
// N/A
var shareable = true;
var replaceIfExists = true;
var file = document.getElementById('fileToUpload').files[0];
var fileSize = file.size;
_bc.file.prepareFileUpload(
"cloudPath", "cloudFilename", shareable, replaceIfExists, fileSize,
function(result) {
if (result.status == 200) {
var uploadId = result.data.fileDetails.uploadId;
_bc.file.uploadFile(xhr, file, uploadId);
}
}
);
// Cloud Code only. To view example, switch to the Cloud Code tab
var cloudPath = "test/files/"
var cloudName = "testCloudFile.dat"
var shareable = true;
var replaceIfExists = true;
var fileSize = 256;
var localPath = "path/to/my/file.dat";
var fileProxy = bridge.getFileServiceProxy();
var retVal = fileProxy.prepareUserUpload(cloudPath, cloudName, shareable, replaceIfExists, fileSize, localPath);
var cloudPath = "test/files/"
var cloudName = "testCloudFile.dat"
var shareable = true;
var replaceIfExists = true;
var fileSize = 256;
var localPath = "path/to/my/file.dat";
var fileProxy = bridge.getFileServiceProxy();
var retVal = fileProxy.prepareUserUpload(cloudPath, cloudName, shareable, replaceIfExists, fileSize, localPath);
JSON Response
{
"status":200,
"data":{
"fileDetails":{
"updatedAt":1452616408147,
"fileSize":100,
"fileType":"User",
"expiresAt":1452702808146,
"shareable":true,
"uploadId":"cf9a075c-587e-4bd1-af0b-eab1a79b958f",
"createdAt":1452616408147,
"profileId":"bf8a1433-62d2-448e-b396-f3dbffff44",
"gameId":"99999",
"path":"dir1/dir2",
"filename":"filename",
"replaceIfExists":true,
"cloudPath":"bc/g/99999/u/bf8a1433-62d2-448e-b396-f3dbffff44/f/dir1/dir2/filename"
}
}
}
Common Error Code
Status Codes
Code | Name | Description |
---|---|---|
40429 | UPLOAD_FILE_TOO_LARGE | File maximum file size exceeded |
40430 | FILE_ALREADY_EXISTS | File exists, replaceIfExists not set |