Skip to main content

Tag-based version management

  • You can operate multiple versions for the same filename by adding an optional tag.
  • Example:
    • Items.json (no tag)
    • Items.json (tag = v1)
    • Items.json (tag = v2)
Lookup behavior:
  • If tag is provided, it resolves the object with exact filename + tag match.
  • If tag is omitted, it first resolves the untagged object.
  • If no untagged object exists, it resolves the most recently updated tagged object for that filename.

Get file metadata

await HyperX.Core.PublicStorage.GetMeta("filename");
  • Fetches file overview metadata.
  • GetMeta returns Task<ObjectMeta>.
  • To query a specific version, use the tag named argument.
    await HyperX.Core.PublicStorage.GetMeta("Items.json", tag: "v2");
    
    • ObjectMeta has the following shape.
    public readonly struct ObjectMeta
    {
        public readonly string Hash; // Hash code of the file (changes when content changes)
        public readonly string Type; // MIME type (example: "image/png")
        public readonly long Size; // File size in bytes
        public readonly DateTimeOffset UpdatedAt; // Last update timestamp
    }
    

Get file hash

await HyperX.Core.PublicStorage.GetHash("filename");
  • If you only need the hash, use GetHash instead of GetMeta.
  • GetHash returns Task<string>.
  • To query a specific version, use the tag named argument.
    await HyperX.Core.PublicStorage.GetHash("Items.json", tag: "v2");
    

Download file

Download file content into memory

HyperX.Core.PublicStorage.Get("filename");
HyperX.Core.PublicStorage.Get("Items.json", tag: "v2");

Download file content to storage

HyperX.Core.PublicStorage.Get("filename", "save-path");
HyperX.Core.PublicStorage.Get("Items.json", "save-path", "v2");

Details

  • Downloads the actual file content.
  • Get returns FileDownloadProgress.
    • FileDownloadProgress has the following shape.
    public class FileDownloadProgress
    {
        public Task<byte[]> File; // File content
        public long FileSize; // Total file size in bytes
        public long DownloadedSize; // Downloaded file size in bytes so far
        public double Progress; // Download progress from 0 to 100
        public FileDownloadStatus Status; // Status of the file download task
    }
    
    public enum FileDownloadStatus
    {
        PENDING = 0,
        IN_PROGRESS = 1,
        COMPLETE = 2,
        FAILURE = 3
    }
    
  • If you provide a save path as the second argument to Get, the File value will be null after completion.
    • The task itself still completes when download succeeds.
  • In Unity, when a save path is provided, the file is downloaded under Application.persistentDataPath.

Unity example

The example below checks if the latest file is already downloaded, downloads when needed, and uses it.
using System.IO;
using UnityEngine;
using UnityEngine.UI;

public class Sandbox : MonoBehaviour
{
    public Image imageComponent;

    private HyperX.Http.FileDownloadProgress fileDownloadProgress;

    async void Start()
    {
        string fileName = "hyperx.png";
        string downloadPath = "/AdditionalAssets/hyperx.png";

        string serverHash = await HyperX.Core.PublicStorage.GetHash(fileName);
        string localHash = PlayerPrefs.GetString($"DOWNLOADED_FILE_HASH:{fileName}");
        if (serverHash == localHash)
        {
            Debug.Log("Latest file is already downloaded.");
        }
        else
        {
            Debug.Log("Starting file download.");
            fileDownloadProgress = HyperX.Core.PublicStorage.Get("hyperx.png", downloadPath);
            await fileDownloadProgress.File;
            PlayerPrefs.SetString($"DOWNLOADED_FILE_HASH:{fileName}", serverHash);
            Debug.Log("File download completed.");
        }

        byte[] imageByte = File.ReadAllBytes(Application.persistentDataPath + downloadPath);
        Texture2D texture = new Texture2D(200, 200);
        texture.LoadImage(imageByte);
        Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
        imageComponent.sprite = sprite;
    }

    void Update()
    {
        if (
            fileDownloadProgress != null
            && fileDownloadProgress.Status == HyperX.Http.FileDownloadStatus.IN_PROGRESS
        )
        {
            Debug.Log($"File download progress: {fileDownloadProgress.Progress}%");
        }
    }
}