question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

API to check if file is available in File Management

Hi,

I wanted to know if there's any API which I can use to get the status of a file before requesting it to download.

Thanks!

apis
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

There is an admin API GetContentList that can be used to list all contents of the title and get statistics such as size. If you call this API, it will return a content list which like the following one.

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
  "code": 200,
  "status": "OK",
  "data": {
    "ItemCount": 2,
    "TotalSize": 13100,
    "Contents": [
      {
        "Key": "a.jpg",
        "Size": 13000,
        "LastModified": "0001-01-01T00:00:00Z"
      },
      {
        "Key": "subfolder/b.txt",
        "Size": 100,
        "LastModified": "0001-01-01T00:00:00Z"
      }
    ]
  }
}
3 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.

Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq commented ·

@Sarah Zhang And Can I run this on server side? I read somewhere that Admin API is not supported in cloud code.

0 Likes 0 ·
Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq commented ·

I have created a http request in cloud code for getting content list but I'm getting a complete response in Unity but I only want to get the content data part in my response. How can I do that?

handlers.fetchFilesList = function(args,context){
    var headers={
        "X-SecretKey": "Redacted"
    };
    
    var body={};
    var url = "https://{Redacted}.playfabapi.com/Admin/GetContentList";
    var content = JSON.stringify(body);
    var httpMethod = "post";
    var contentType = "application/json";
    
    var response = http.request(url,httpMethod,content,contentType,headers);
    return {responseContent: response};
};
<br>
0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Muhammad Roshaan Tariq commented ·

Please refer to the following code to get the Contents part of the response.

...
var response = JSON.parse(http.request(url,httpMethod,content,contentType,headers)).data.Contents;
...
0 Likes 0 ·