Hey folks,
I'm totally new to Playfab and I'm trying to work through some of its functionality; I cobbled together a bunch of code from tutorials in attempt to get data uploading and downloading. I'm not sure if the uploading is working -- I don't see anything in my Title Data on the site. I tried to download the uploaded data, but that's returning a 403: Forbidden.
The exception is thrown at:
HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
Here's the code, apologies for the mess. I appreciate any help that could be thrown my way. Also, I'm using C#/Monogame/Xamarin, so there's no WWW library readily available like in Unity, which most of the tutorials are based in. Thanks!
public async static void Login(WinForm winForm, string path) { winForm.WriteLine("Initializing..."); PlayFabSettings.DeveloperSecretKey = "[redacted]"; PlayFabSettings.TitleId = "[redacted]"; var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true }; PlayFabResult<LoginResult> loginTask = await PlayFabClientAPI.LoginWithCustomIDAsync(request); winForm.WriteLine("Login complete."); winForm.WriteLine(loginTask.ToString()); winForm.WriteLine("Getting upload key..."); global::PlayFab.AdminModels.GetContentUploadUrlRequest ureq = new global::PlayFab.AdminModels.GetContentUploadUrlRequest { Key = "dndjournal.dat", ContentType = "application/x-gzip" }; PlayFabResult<global::PlayFab.AdminModels.GetContentUploadUrlResult> ures = await PlayFabAdminAPI.GetContentUploadUrlAsync(ureq); winForm.WriteLine(ures.ToString()); if (ures.Error != null) { winForm.WriteLine("Error: " + ures.Error.ToString()); } else { string url = ures.Result.URL; winForm.WriteLine("URL: " + url); GetContentUploadURLSuccess(url, winForm, path); } winForm.WriteLine("Complete."); GetContentDownloadURL(winForm); } static void GetContentUploadURLSuccess(string url, WinForm winForm, string path) { winForm.WriteLine(string.Format("Endpoint URL Recieved: {0}", url)); byte[] data = File.ReadAllBytes(path); PutFile(url, data, winForm); } public static void PutFile(string putURL, byte[] payload, WinForm winForm) { var request = (HttpWebRequest)WebRequest.Create(putURL); request.Method = "PUT"; request.ContentType = "application/x-gzip"; if (payload != null) { Stream dataStream = request.GetRequestStream(); dataStream.Write(payload, 0, payload.Length); dataStream.Close(); winForm.WriteLine("Upload complete."); } else { winForm.WriteLine(string.Format("ERROR: Byte arrry was empty or null")); return; } } static async void GetContentDownloadURL(WinForm winForm) { winForm.WriteLine("Downloading..."); GetContentDownloadUrlRequest request = new GetContentDownloadUrlRequest(); request.Key = "dndjournal.dat"; request.HttpMethod = "GET"; request.ThruCDN = true; PlayFabResult<GetContentDownloadUrlResult> result = await PlayFabClientAPI.GetContentDownloadUrlAsync(request); winForm.WriteLine(result.Result.URL); GetFile(result.Result.URL, winForm); } static void GetFile(string getURL, WinForm winForm) { var request = (HttpWebRequest)WebRequest.Create(getURL); request.Method = "GET"; request.ContentType = "application/x-gzip"; HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse(); Stream responseStream = webResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); string s = streamReader.ReadToEnd(); winForm.WriteLine("Data stream: " + streamReader.BaseStream.Length.ToString()); }
Test test