public bool UploadFile( string cloudPath, string cloudFilename, bool shareable, bool replaceIfExists, string localPath, SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { #if UNITY_WEBPLAYER || UNITY_WEBGL throw new Exception("FileUpload API is not supported on Web builds use FileUploadFromMemory instead"); #else Stream info = new FileStream(localPath, FileMode.Open); if (info.Length == 0) { _client.Log("File at " + localPath + " does not exist"); return(false); } byte[] fileData = new Byte[(int)info.Length]; info.Seek(0, SeekOrigin.Begin); info.Read(fileData, 0, (int)info.Length); info.Close(); return(UploadFileFromMemory(cloudPath, cloudFilename, shareable, replaceIfExists, fileData, success, failure, cbObject)); #endif }
/// <summary> /// Prepares a user file upload. On success the file will begin uploading /// to the brainCloud server.To be informed of success/failure of the upload /// register an IFileUploadCallback with the BrainCloudClient class. /// </summary> /// <param name="cloudPath">The desired cloud path of the file</param> /// <param name="cloudFilename">The desired cloud fileName of the file</param> /// <param name="shareable">True if the file is shareable</param> /// <param name="replaceIfExists">Whether to replace file if it exists</param> /// <param name="localPath">The path and fileName of the local file</param> /// <param name="success">The success callback</param> /// <param name="failure">The failure callback</param> /// <param name="cbObject">The callback object</param> public bool UploadFile( string cloudPath, string cloudFilename, bool shareable, bool replaceIfExists, string localPath, SuccessCallback success = null, FailureCallback failure = null, object cbObject = null) { #if UNITY_WEBPLAYER || UNITY_WEBGL throw new Exception("FileUpload API is not supported on Web builds use FileUploadFromMemory instead"); #else FileInfo info = new FileInfo(localPath); if (!info.Exists) { _client.Log("File at " + localPath + " does not exist"); return(false); } Dictionary <string, object> data = new Dictionary <string, object>(); data[OperationParam.UploadLocalPath.Value] = localPath; data[OperationParam.UploadCloudFilename.Value] = cloudFilename; data[OperationParam.UploadCloudPath.Value] = cloudPath; data[OperationParam.UploadShareable.Value] = shareable; data[OperationParam.UploadReplaceIfExists.Value] = replaceIfExists; data[OperationParam.UploadFileSize.Value] = info.Length; ServerCallback callback = BrainCloudClient.CreateServerCallback(success, failure, cbObject); ServerCall sc = new ServerCall(ServiceName.File, ServiceOperation.PrepareUserUpload, data, callback); _client.SendRequest(sc); return(true); #endif }