File
The File API allows brainCloud users to upload files to their individual accounts. These files can be private to the user, or shareable (public) where anyone with the URL can access the file.
Downloading Files
Downloading files is usually as simple as getting the file URL via the ListUserFiles API and downloading it via whatever method you decide on the platform you are working on. The brainCloud client does not have built in support for downloading files.
Pro-tip: There are two URLs for file downloading, downloadUrl and cdnUrl, in our file system.
- The downloadUrl is a persistant URL that automatically redirects to a CDN URL (if enabled) when called
- The cdnUrl is a temporary URL that is good for downloading the file right away (in an hour from the time to generate that URL)
Apps do not have to specifically retrieve the CDN urls of files. brainCloud will automatically redirect the client to the CDN address when a download attempt is made.
Shared Files
If the file you are downloading is shared publically (shareable = true) by the owner then there are no special steps required to download. Simply get the file URL and download.
Private Files
If the file you want to download is private, and therefor only accessible by the owner there is another step to successfully downloading the file. To ensure that the person downloading the file is the owner you must append an active Session ID from the file owner to the file URL as a query parameter.
To get the session ID simply call the GetSessionId
method of the BrainCloudClient. Here is an example URL with the Session ID appended:
https://api.braincloudservers.com/downloader/bc/g/123465/u/fe32f00f-9eda-4047-83b1-120b3398b14b/f/TestFile.dat?sessionId=l92dmkua0aqvb4egtid3fn14n7
API Summary
Managing Uploads
Monitoring Uploads
File Management
JavaScript Methods
Unity Methods
📄️ CancelUpload
Method cancels an upload. If a File Upload Callback has been registered with the class, the fileUploadFailed callback method will be called once the upload has been canceled.
📄️ DeleteUserFile
Deletes a single user file.
📄️ DeleteUserFiles
Deletes multiple user files.
📄️ GetCDNUrl
This method was added to support clients (like very old versions of Unity - i.e. circa 2016) that cannot handle HTTP Redirects. This method allows clients to pre-resolve the CDN endpoint for the file to download.
📄️ GetUploadBytesTransferred
Returns the number of bytes uploaded or -1 if upload not found.
📄️ GetUploadProgress
Returns the progress of the given upload from 0.0 to 1.0 or -1 if upload not found.
📄️ GetUploadTotalBytesToTransfer
Returns the total number of bytes that will be uploaded or -1 if upload not found.
📄️ ListUserFiles
List all user files
📄️ 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 .file.uploadFile method.
📄️ UploadFile - JavaScript
Method uploads the supplied file to the 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:
📄️ UploadFile
Prepares a user file upload. On success the file will begin uploading to the server.
📄️ UploadFileFromMemory
Upload screenshots from memory instead of local file storage. On success the file will begin uploading to the server.