question

jamezila avatar image
jamezila asked

403 from Content Download

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

Content
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

We have tested your code and it seems there is no error in your code. However we succeed in reproducing your issue. We got the same 403 error due to the non-exist key in the GetContentDownloadUrlRequest. Please check in the [Game Manager] -> [Content] -> [File Management], does dndjournal.dat exist there?

Generally speaking, PlayFab service will not respond a 403 error even when authentication failure. This could be an ISP issue. It is better to try a network capture so that you can quickly locate your issue.

Besides, in terms of content service, please see this thread for more information.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jamezila avatar image jamezila commented ·

Sorry -- I don't understand most of your response.

If you got the same 403 error, how can the fault be with my ISP?

The [Content]->[File Management] section does not have a Key field. The [Players]->[Player]->[Player Data (Title)] section does. Maybe I'm trying to do the wrong thing; I'd like for a player to be able to upload and download content. Sounds like I'm going about this all wrong; can you point me in the right direction?

0 Likes 0 ·
brendan avatar image brendan jamezila commented ·

If you're specifically trying to upload from the client, I'd suggest reading this thread:

https://community.playfab.com/questions/18913/allow-users-to-upload-files-with-cdn.html

But I can also add that we are going to be releasing our new commerce model, which includes a complete UGC service, in preview shortly (https://blog.playfab.com/blog/upcoming-roadmap-2018-q4-oct-dec-edition).

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.