Mythcl
Mythcl

Reputation: 1

Thirdweb UnitySDK: storage.Upload gets stuck in WEBGL build

I have a line which uploads new metadata to ipfs, but it just freezes in WEBGL build (does not log an error either) IPFSUploadResult newURI = await ThirdwebManager.Instance.SDK.storage.UploadText(jsonMeta);

It did work when I ran it in editor though, so It must be something related to how WEBGL builds work...

the Function: (gets stuck at the storage.UploadText() (nothing gets executed after that either))

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...");
    }
}

I've tried to UploadFromPath, but it froze aswell...

EDIT: Did some digging around and found some threads that said that webgl does not support System.IO.File which thirdweb UnitySDK uses to upload to ipfs

Though, shouldn't it throw an error in that case not just silently freeze?

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

Upvotes: 0

Views: 128

Answers (1)

Mythcl
Mythcl

Reputation: 1

Dont know what was the actual problem behind this, but the fix was to change this line in StorageUploader.cs

        System.IO.File.WriteAllTextAsync(path, text); -> 
        System.IO.File.WriteAllText(path, text);

Upvotes: 0

Related Questions