///<summary>Uploads an AssetBundle to RESTful service ///<param name="url">The absolute URL to the POST endpoint</param> ///<param name="info">The AssetBundleInfo struct</param> ///<param name="message">A message to be used on the server side</param> ///<param name="jwtName">Optional name of a JSON Web Token (placed somewhere in Assets) that can be used for authentication</param> ///<exception cref="FileNotFoundException">The AssetBundle is not found</exception> ///<returns>Returns a Task so can be used with await or ContinueWith</returns> ///</summary> public static Task <HttpResponseMessage> UploadAssetBundleAsync(string url, AssetBundleInfo info, FCMMessage message, string appName = null, string jwtName = null) { bool useJWT = !string.IsNullOrEmpty(jwtName); if (info.Exists()) { if (useJWT) { client.DefaultRequestHeaders.Authorization = GenerateAuthHeaderFromJWT(jwtName); } MultipartFormDataContent formData = new MultipartFormDataContent(); FileInfo f = new FileInfo(info.path); StreamContent fs = new StreamContent(f.OpenRead()); formData.Add(fs, "bundle", f.Name); string app = !string.IsNullOrEmpty(appName) ? appName : Application.productName; formData.Add(new StringContent(app), "appName"); if (message.IsValid()) { formData.Add(new StringContent(message.Serialize()), "message"); } return(client.PostAsync(url, formData)); } else { throw new FileNotFoundException(string.Format("AssetBundle {0} does not exist in directory {1}", info.name, info.path)); } }
public static FCMMessage Deserialize(string val) { FCMMessage obj = JsonUtility.FromJson <FCMMessage>(val); return(obj); }
///<summary>Simplified version of <see cref="UploadAssetBundleAsync" /> ///<param name="url">The absolute URL to the POST endpoint</param> ///<param name="info">The AssetBundleInfo struct</param> ///<param name="message">A message to be used on the server side</param> ///<param name="jwtName">Optional name of a JSON Web Token (placed somewhere in Assets) that can be used for authentication</param> ///<exception cref="FileNotFoundException">The AssetBundle is not found</exception> ///<returns>Returns a Task which returns a deserialized RemoteAssetBundle</returns> ///</summary> public static async Task <RemoteAssetBundle> UploadAssetBundle(string url, AssetBundleInfo info, FCMMessage message, string appName = null, string jwtName = null) { HttpResponseMessage response = await UploadAssetBundleAsync(url, info, message, appName, jwtName); string content = await response.Content.ReadAsStringAsync(); Debug.Log(content); return(RemoteAssetBundle.Deserialize(content)); }