question

voxelghost avatar image
voxelghost asked

Trying to load AssetBundle from CDN, GetContentDownloadUrl error

I'm trying to load an AssetBundle from the Playfab CDN, and the first time I call the PlayFabClientAPI.GetContentDownloadUrl it gives me a nice URL, which works, and I manage to download the Asset Bundle Manifest.

But the second time, when I'm trying to load a Scene, the PlayFabClientAPI.GetContentDownloadUrl call returns an URL that doesn't work...

*This works* (first time calling GetContentDownloadUrl, to get Asset Bundle Manifest)

https://cdn.playfab.com/5ba2/etc/Android/Android?Expires=1497639528&Signature=geN1ERFgqdnNrkzk2-0UDerCyO~IdwvC-SrroNIKy8BbtqVoy5mgx2nGcUOYipHgQDtT4RZquPOl55q98nCohF-o4q2S8tnGRzBtqxQYf0JDCoJPlDWWppUdEuLDZtpK1L0MtKcOjo4wC71sE4KakuJNHvqs6xSOsgeaFZE9cHo_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA


*This doesnt* (second time calling GetContentDownloadUrl, to get the Scene Bundle)

https://cdn.playfab.com/5ba2/etc/Android/admiregames_5ba2?Expires=1497639529&Signature=PAzkFPGsvkvHtaRY2lShr8Ll1ZXAwQH3vk07eqrBBUIyoemzC-JDGqF2Msk7oVSnVE8UxIXXGpeSWDsEdvfc9~iD4xhlAbvSR1vwS~SdmqHEi8-uQGl-VJEEEWMwDBF8YY073ju3odDeruP~pMkN4MKiRTwcghXuCivXMbtqJBE_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

In both cases, those are pre-signed download URLs from AWS CloudFront, so there's no reason one would work and not the other (assuming the expiration time from when the URL was requested hasn't expired). And in my own testing, I'm able to get both files via the returned download URLs without any issues. Can you please provide the specifics on how you're requesting the URL, and how you're using it for the download attempt?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

voxelghost avatar image
voxelghost answered

This is my function that should get the URL and then download the file:

protected IEnumerator InstantiateGameSceneAsync(string assetBundleName, string bundleName, string assetSceneName)
    {
        // This is simply to get the elapsed time for this phase of AssetLoading.
        float startTime = Time.realtimeSinceStartup;

        var isDone = false;
        var urlParams = string.Empty;

        //We have to make a call to playfab to get the URL for each asset bundle that we want to download.
        PlayFabClientAPI.GetContentDownloadUrl(new GetContentDownloadUrlRequest()
        {
            Key = assetBundleName,
            HttpMethod = "GET"
        }, (getContentResult) =>
        {
            //Get the URL Params (AWS Security)
            urlParams = getContentResult.URL.Split('?')[1];
            //Flag that we are done calling playfab
            isDone = true;
        }, PlayFabErrorHandler.HandlePlayFabError);


        //Wait for PlayFabs Callback
        while(!isDone)
            yield return new WaitForSeconds(.1f);

        Debug.Log("isDone: " + isDone);

        // Load scene from assetBundle.
        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(bundleName, assetSceneName, false, urlParams);
        if (request == null)
            yield break;
        yield return StartCoroutine(request);

        // Calculate and display the elapsed time.
        float elapsedTime = Time.realtimeSinceStartup - startTime;
        Debug.Log(assetSceneName + (request == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds");
    }

But when I run this it return 403 Acces Forbidden (in the debug: )

Failed downloading bundle admiregames_5ba2 from https://cdn.playfab.com/5ba2/etc/Android/admiregames_5ba2?Expires=1497693184&Signature=Ybh~XIlgtSyvggO50jXGvz46W8wwOlpAMJY05VCoaiRKmYpIPkLwvIwQatbNPFXskXNcraBLbVbBBsjhz2V5FRqLRcwf6RAlekmAp-qCCqb7EPGQKPDqjO56b-jdlRIYCArYXc38Th9A7yHvbPPLfvQL7hwr5uxniRLDHJKifQY_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA: 403 Forbidden
9 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.

voxelghost avatar image voxelghost commented ·

And also, when I copy+paste the link to a browser it doesn't download the file but return a page with only this content:

<Error><Code>AccessDenied</Code><Message>Access denied</Message></Error>
0 Likes 0 ·
brendan avatar image brendan voxelghost commented ·

If you're getting AccessDenied, either the URL is being altered in some way, or the signature has expired. Can you try getting a fresh URL from GetContentDownloadUrl in Postman and using that in your browser? When I do that, I get the file just fine for your title. That would indicate that there's no issue retrieving the file, and we should focus on what's happening to the URL in your code after it has been returned.

0 Likes 0 ·
voxelghost avatar image voxelghost brendan commented ·

Yes it also works me in Postman. I also think that the problem is around the retrieving of the file... Still figuring out

0 Likes 0 ·
voxelghost avatar image voxelghost commented ·

Okay I solved it, it was my problem. Getting the URL now works, but loading it still doesn't, but I guess it's my problem too :P Thanks for the answer @Brendan tho

0 Likes 0 ·
brendan avatar image brendan voxelghost commented ·

What's the problem you're seeing with loading it, at this point?

0 Likes 0 ·
voxelghost avatar image voxelghost brendan commented ·

My problem what I get in the debug is:

Scene '5BA2_PreStart' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
To add a scene to the build settings use the menu File->Build Settings...
UnityEngine.SceneManagement.SceneManager:LoadSceneAsync(String, LoadSceneMode)
AssetBundles.AssetBundleLoadLevelOperation:Update() (at Assets/AssetBundleManager/AssetBundleLoadOperation.cs:92)
AssetBundles.AssetBundleManager:Update() (at Assets/AssetBundleManager/AssetBundleManager.cs:491)

So I guess the problem is that pproblably have a mistake in downloading the whole AssetBundle, so it can't find the '5BA2_PreStart' Scene...

0 Likes 0 ·
Show more comments

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.