You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Thirdweb Unity SDK存储上传(Upload)在WebGL构建中无响应冻结的问题求助

Thirdweb Unity SDK存储上传(Upload)在WebGL构建中无响应冻结的问题求助

我碰到了一个头疼的问题:我写了一段上传新元数据到IPFS的代码,在WebGL构建版本里直接卡住冻结了,连错误日志都没输出。但这段代码在Unity编辑器里运行完全正常,所以问题肯定和WebGL构建的运行机制有关。

核心的上传代码是这一行:

IPFSUploadResult newURI = await ThirdwebManager.Instance.SDK.storage.UploadText(jsonMeta);

下面是完整的调用函数,问题就出在storage.UploadText()这一步——执行到这里之后,后面的代码完全不会运行:

public async void updateNFTMedadata(CharacterData character) {
    if (!_isUpdatingCharacter) {
        _isUpdatingCharacter = true;
        Asyncloader.Instance.setLoadingScreenText("Updating character data...");
        Debug.Log("Started updating character...");

        Contract contract = ThirdwebManager.Instance.SDK.GetContract(GameContracts.characters);
        Debug.Log("Contract fetched...");

        string jsonMeta = getUpdatedCharacterMetadataString(character);
        Debug.Log("jsonMetaString generated: " + jsonMeta);

        IPFSUploadResult newURI = await ThirdwebManager.Instance.SDK.storage.UploadText(jsonMeta);
        Debug.Log("Data uploaded...");

        string _tokenId = character.token_id;
        string _uri = "ipfs://" + newURI.IpfsHash;
        string[] argsObj = { _tokenId, _uri };
        string args = JsonConvert.SerializeObject(argsObj);

        Debug.Log("Writing data...");
        TransactionResult result = await contract.Write("setTokenURI", args);
        Debug.Log("Writing data...");

        Asyncloader.Instance.updateCharacterList();
        _isUpdatingCharacter = false;
        Asyncloader.Instance.setLoadingScreenText("");
        Debug.Log("Ended updating character...");
    }
}

我还尝试过用UploadFromPath方法,结果还是一样卡住。


后来我自己查了些资料,发现有帖子说WebGL并不支持System.IO.File,而Thirdweb Unity SDK的上传功能刚好用到了这个类。但让我困惑的是:如果是这个原因,为什么程序不抛出错误,而是直接静默冻结呢?

顺便贴一下我找到的Thirdweb SDK里UploadText的源码:

public async Task<IPFSUploadResult> UploadText(string text)
{
    var path = Application.temporaryCachePath + "/uploadedText.txt";
    await System.IO.File.WriteAllTextAsync(path, text);
    return await UploadFromPath(path);
}

备注:内容来源于stack exchange,提问作者Mythcl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 10:24:51