Esempio n. 1
0
        public static bool UploadFileToCDN(string relativeFileName, byte[] content)
        {
            GetContentUploadUrlRequest request = new GetContentUploadUrlRequest();

            request.ContentType = "binary/octet-stream";
            request.Key         = relativeFileName;


            var result = PlayFabAdminAPI.GetContentUploadUrlAsync(request).GetAwaiter().GetResult();

            if (result.Error == null)
            {
                bool uploadResult = UploadFile(result.Result.URL, content);
                //HttpClient client = new HttpClient();
                //ByteArrayContent data = new ByteArrayContent(content);
                //var response = client.PutAsync(result.Result.URL, data).GetAwaiter().GetResult();

                if (uploadResult)
                {
                    return(true);
                }
                else
                {
                    Console.WriteLine("HTTP PUT ERROR" + " " + result.Result.URL);
                }
            }
            else
            {
                Console.WriteLine(result.Error.ErrorMessage);
            }
            return(false);
        }
Esempio n. 2
0
        private async Task <bool> UploadAsset(string key, string path)
        {
            var request = new GetContentUploadUrlRequest()
            {
                Key         = key,
                ContentType = "application/x-gzip"
            };

            LogToFile("\tFetching CDN endpoint for " + key);
            if (token.IsCancellationRequested)
            {
                return(true);
            }

            var getContentUploadTask = await PlayFabAdminAPI.GetContentUploadUrlAsync(request);

            //getContentUploadTask.Wait();

            if (getContentUploadTask.Error != null)
            {
                OutputPlayFabError("\t\tAcquire CDN URL Error: ", getContentUploadTask.Error);
                return(false);
            }

            var destUrl = getContentUploadTask.Result.URL;

            LogToFile("\t\tAcquired CDN Address: " + key, ConsoleColor.Green);

            byte[] fileContents = File.ReadAllBytes(path);

            return(await PutFile(key, destUrl, fileContents));
        }
Esempio n. 3
0
        async public static Task <bool> UploadFile(string titleId, DownloadedFile fileInfo)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;

            var key    = fileInfo.FilePath.Split('/').ToList()[fileInfo.FilePath.Split('/').ToList().Count - 1];
            var type   = MimeMapping.GetMimeMapping(key);
            var result = await PlayFabAdminAPI.GetContentUploadUrlAsync(
                new GetContentUploadUrlRequest()
            {
                Key         = fileInfo.Data.Key,
                ContentType = type
            }
                );

            if (result.Error != null)
            {
                Console.WriteLine(PlayFabUtil.GetErrorReport(result.Error));
                return(false);
            }
            PlayFabSettings.TitleId            = currentPlayFabTitleId;
            PlayFabSettings.DeveloperSecretKey = currentDevKey;

            bool success = await PlayFabExtensions.UploadFile(result.Result.URL, fileInfo.FilePath);

            if (!success)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public static void UploadFile(string titleId, CdnFileDataMigration.UploadFile fileInfo, Action <bool> callback)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;

            var key  = fileInfo.FilePath.Split('/').ToList()[fileInfo.FilePath.Split('/').ToList().Count - 1];
            var type = MimeMapping.GetMimeMapping(key);

            PlayFabAdminAPI.GetContentUploadUrlAsync(new GetContentUploadUrlRequest()
            {
                Key         = fileInfo.Data.Key,
                ContentType = type
            }).ContinueWith((result) =>
            {
                PlayFabSettings.TitleId            = currentPlayFabTitleId;
                PlayFabSettings.DeveloperSecretKey = currentDevKey;
                PlayFabExtensions.UploadFile(result.Result.Result.URL, fileInfo.FilePath, callback);
            });
        }