Skip to main content
Version: 5.7.0

UploadFile - JavaScript

Method uploads the supplied file to the brainCloud server. Note that you must call prepareUserUpload to retrieve the uploadId before calling this method. It is assumed that any methods required to monitor the file upload including progress, and completion are attached to the XMLHttpRequest xhr object's events such as:

  • xhr.upload.addEventListener("progress", uploadProgress);
  • xhr.addEventListener("load", transferComplete);
  • xhr.addEventListener("error", transferFailed);
  • xhr.addEventListener("abort", transferCanceled);

On a 200 http status, the JSON return is available from XMLHttpRequest.responseText

ServiceOperation
fileUPLOAD_FILE

Method Parameters

ParameterDescription
xhrThe XMLHttpRequest object that the brainCloud client will use to upload the file
fileThe file object
uploadIdThe upload id obtained via prepareFileUpload()

Usage

http://localhost:3000
// N/A
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

The XMLHttpRequest object will return a 200 http status if the upload is successful.