question

Kim Strasser avatar image
Kim Strasser asked

How can a player download new level files via global CDN?

I have uploaded a text file named Level1.txt but I don't know how to download the file in the client. How can the client download a level file automatically after it was released in File Management? Which API call should I use in the client?

Where exactly is the file saved when the client downloads it? Does it depend on the iOS/Android device?

How can I find out if the client has already downloaded a certain level file? Normally, the client doesn't need to download a level file a second time.

Is it possible to download certain text files even if the client has already downloaded them before? I want to create one or two text files that I update from time to time, and those files need to be downloaded and replaced on the clients device right after I uploaded a new version of those files in File Management.

But how can the client know if he needs to download and replace a text file that he already has downloaded a few days or weeks ago?

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

·
Sarah Zhang avatar image
Sarah Zhang answered

>> How can the client download a level file automatically after it was released in File Management? Which API call should I use in the client?

Downloading the asset via code is a two-step process.

  1. First, make a call to GetContentDownloadUrl and obtain a pre-signed URL that will authorize your download.
  2. You then use the pre-signed URL to make an HTTP GET request, and fetch the data.

You can check this section Fetching assets for more details, this section provides a code snippet that shows the bare bones of the process. About the part of automatically” downloading assets, it’s not a built-in feature.Game developers need toimplement the automatically” downloading feature in the client code by themselves. There is an API GetContentList can be used to List all contents of the title and get statistics such as size. You can add a prefix in the request body to limit the response to keys that begin with the specified prefix. You can use prefixes to list contents under a folder, or for a specified version, etc. Refer to the following content as a possible workaround.

  1. Adding the version number in the content filename’s prefix.
  2. Write a verification method A can to get the prefix from CloudScript, then compare the latest content’s version with the local file, verify if version number has changed.
  3. Call the method A in the call back function of login function.
  4. If version number has changed then download the content file via Http GET requests.

>> Where exactly is the file saved when the client downloads it? Does it depend on the iOS/Android device?

On PC, it depends on how you write the code of saving files, you can choose the file path you want. The same goes for other devices. The specific situation is affected by the development rules of different platforms. You check the API of corresponding languages to learn how to set the file path when saving files.

>> How can I find out if the client has already downloaded a certain level file?

You can find out if a file has existed via client language’s API. For example, on C#, you can check the methods under Directory Class.

>> Is it possible to download certain text files even if the client has already downloaded them before? I want to create one or two text files that I update from time to time, and those files need to be downloaded and replaced on the clients device right after I uploaded a new version of those files in File Management.

Yes, it’s possible to download certain text files even if the client has already downloaded them before. If you mean you want to let different versions of files have same filename, you may need to use “LastModified” or other info to distinguish between different versions of files instead of using “Key”(filename). You also need to implement the replacing file feature via client language’s API.

>> But how can the client know if he needs to download and replace a text file that he already has downloaded a few days or weeks ago?

For example store the latest version number as a Title data K/V pair or in the CloudScript, let clients get them every time when they logged in. Then do the verification and downloading. You can refer to the first answer for a possible process.

6 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.

Kim Strasser avatar image Kim Strasser commented ·

What is the best way to add an updated version of a text file in File Management?

For example, I have uploaded this file on January 12, 2020 4:58 PM: Root/Levelfiles/Level1.txt

Now, I want to update the text file because there is something wrong in this file. But some players have already downloaded the current version of the file. I want that all players download and replace this file as soon as possible on their iOS/Android device.

How should I proceed to upload the new version of the text file in this case?

Should I delete the current version of Level1.txt first in File Management?

Can I immediately upload the new Level1.txt after deleting the current Level1.txt in File Management?

Can I use the same file name "Level1.txt" or is it necessary that I change the file name so that the client can distinguish his current version(saved on the players iOS/Android device) and the new version of "Level1.txt" in File Management? Because the client always needs to download the new version of a file if a new version is available in File Management.

I have not understand if I need to change the file name or if I need to change something different in my Level1.txt file.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Kim Strasser commented ·

Refer to the doc Content Delivery network quickstart. If your target is completely “overwrite” the original file on the cloud, you just need to upload the new file that has different content and the same name. “Level1.txt” in the file management will be replaced with the new content “Level1.txt”, if so the old file will appear to users for up to 24 hours, until it's overwritten with the new file. Deleting the old files “Level1.txt” then uploading a new “Level1.txt” will also take 24 hours to removes the old files from all edge locations on the cloud.

If you want the new file can be available immediately, you need to use a new file name, like 20200116Level01.txt. Or you can upload the new file in another folder of file management. For example, the older file is in “v1/Level1.txt”, the new file should be in”v1fix/Level1.txt”. You can choose the most suitable way for your project.

When downloading this new file that has the same file name as the previous one,you need to implement the “overwriting original files” feature via client code.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Sarah Zhang commented ·

How can I use GetContentList in cloud script?

I want to list all the files of the folder Levelfiles that have the prefix "Version" in the filename. For example the file Version_1_Level1.txt.

But I get this error:

"Error": {
            "Error": "JavascriptException",
            "Message": "JavascriptException",
            "StackTrace": "ReferenceError: admin is not defined\n    at handlers.ListContentFiles (BFD0A-main.js:21:17)\n    at Object.invokeFunction (Script:116:33)"
        }
handlers.ListContentFiles = function (args, context)
{
   var result = admin.GetContentList({Prefix: "Version"});
   var clientcurrentfileversion = args.FileVersion;
   var NumberofFiles = 0;
   
   if (result != null)
   {
       NumberofFiles = result.Result.ItemCount;
   }
   else
       log.info("Could not get files.");
   
   return NumberofFiles;
}
0 Likes 0 ·
Show more comments
Show more comments
Sarah Zhang avatar image Sarah Zhang Kim Strasser commented ·

These reference steps are simplified steps. It supposes you will manually update the version number in Cloud Script or in title internal data. It doesn't suppose you will call GetContentList API on CloudScript.

>> Is it not possible to list all the files with a certain prefix("Version") in cloud script or directly in the client? Is it necessary that I use a custom game server when I want to list all the files with a certain prefix?

Technically considering, it’s possible to call Admin API on CloudScript(via Http request). But considering the security and the limits of Admin API, it’s not recommended. Except for the custom server, you can build an administrator tool by yourself, it can be an application that used for general game configurations. You can list the latest contents using the admin tool, then store the info to title data or internal title data, so clients or CloudScript can get it.

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.