Hi! I need help I use AWS SDK for getting data (addressables, jsons, etc...) files from S3 bucket. For example: Code (CSharp): AmazonS3Client cr = new AmazonS3Client("key1", "key2", new AmazonS3Config { ServiceURL = "https://" + "myUrl", MaxErrorRetry = 0, Timeout = TimeSpan.FromSeconds(60) } ); var downloadRequest = new GetObjectRequest { Key = "myFilePath", BucketName = "bucketName" }; var getObjectResponse = await cr.GetObjectAsync(downloadRequest, cts.Token).AsUniTask(); (Of course, I replaced real values to fictional) Also, I use UniTask package for async. It works perfect for next build platforms: PC, Android, IOS. But if I build WebGL, any request to this API return the <TypeInitializationException> like this: System.TypeInitializationException: The type initializer for 'Amazon.Util.Internal.RegionFinder' threw an exception. ---> System.ArgumentNullException: Value cannot be null. Parameter name: stream at System.IO.StreamReader..ctor (System.IO.Stream stream, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize, System.Boolean leaveOpen) [0x00000] in <00000000000000000000000000000000>:0 I used all the advice I found on the Internet: - Added a link.xml file indicating AWS - Corrected versions of AWS and its dependencies (microsoft.bcl.asyncInterfaces, etc...) - Changed types of compression and decompression - Tried to combine different versions of libraries, etc. Anyway, it not worked and throw TypeInitializationException. How it can be fixed? Or AWS SDK not worked in WebGL platform? (I used OpenServer for running project) Thank you in advance
The AWS DLLs use some form of webrequest for their communication, that does not work on WebGL (I think). My solution to this problem was using the Javascript SDKs of AWS and this https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
Yes, unfortunately, AWS SDK really not supported in WebGL. They write supported platforms - standalone, android and ios. I finded this here: https://github.com/aws/aws-sdk-unity-net Anyway, i rewrote code to standard UnityWebRequests. Thank you for answer.
Certainly. My application is on the server, and I thought to contact the S3 server every time to get the necessary data. But since it is impossible to do this from WebGL, I pre-determine all files, addressables, etc. to a local folder on the server, and using UnityWebRequest for get data from this folder. And my colleague - a web developer - just wrote a script that, when data changes on the S3 server, automatically also synchronizes this data with the data folder on the server. Here is an example script for getting data from a json file: Code (CSharp): public static async UniTask<string> LoadTextFromServerFile(string filePath) //path example: //service/dictionaries/config.json { using var webRequest = UnityWebRequest.Get(filePath); await webRequest.SendWebRequest().ToUniTask(); var pages = filePath.Split('/'); var page = pages.Length - 1; var result = "Empty"; switch (webRequest.result) { case UnityWebRequest.Result.ConnectionError: case UnityWebRequest.Result.DataProcessingError: case UnityWebRequest.Result.ProtocolError: Debug.LogError(pages[page] + " - Error: " + webRequest.error); break; case UnityWebRequest.Result.Success: Debug.Log(pages[page] + " - Received successfully"); result = webRequest.downloadHandler.text; break; } return result; } And for loading addressables from localPath: Code (CSharp): public async UniTask LoadAddressables(string catalogPath, CancellationToken cancellationToken = default) { Addressables.ClearResourceLocators(); await Addressables.LoadContentCatalogAsync(catalogPath).ToUniTask(cancellationToken: cancellationToken); await UpdateCatalogs().ToUniTask(this); } UpdateCatalogs - just use 2 methods from Addressable package Addressables.CheckForCatalogUpdates(); Addressables.UpdateCatalogs(catalogsToUpdate);
I tried to do this, but the S3 server does not support such requests, it seems Anyway, I didn't manage to do it this way.
S3 support REST api. I'm currently using addressable with S3. Source: https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html Use Code (CSharp): Addressables.WebRequestOverride = WebRequestOverride; In WebRequestOverride, input your s3 credential and compute it using ComputeSigner. Then, add the results into UnityWebRequest headers.
Hi @HelloSpriTe , It looks like an excellent solution for WebGL users. I am also facing the same problem and would like to utilize your solution. But my problem is no matter what UnityWebRequest does not find my LocalFilePath. I am not sure what I am doing wrong. Could you provide some idea?
Hello! Perhaps you specified the paths incorrectly in the addressable settings? There you need to first configure the profile, and then in each group of your addressables you select exactly this profile and the type of path (local or remote), and it will display the appropriate paths. If you send screenshots of your settings, I could compare them with mine.
@manuelgoellnitz Can you provide me with an example of your solution? Did you call the AWSSDK library in your .jslib? or how did you implemented browser scripting?
I made a javascript file with all the communication with AWS and the jslib for the communication with unity. This way I did not need to create a new build when there was an error in the communication with AWS.