aws-sdk-net: Unity : S3Example GetObjects not working. User-Agent header issue

I downloaded latest unity SDK “aws-sdk-unity_3.3.83.0.zip” and installed S3 unitypackage. but in GetObjects function I am getting error. Following is trace of the problem

ArgumentException: Cannot set Request Header User-Agent - name contains illegal characters or is not user-overridable
UnityEngine.Networking.UnityWebRequest.SetRequestHeader (System.String name, System.String value) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/UnityWebRequest/WebRequestBindings.gen.cs:473)
UnityEngine.WWW..ctor (System.String url, System.Byte[] postData, System.Collections.Generic.Dictionary`2 headers) (at /Users/builduser/buildslave/unity/build/Runtime/WebRequestWWW/UWRWWW.cs:60)
Amazon.Runtime.Internal.UnityMainThreadDispatcher+<InvokeRequest>d__7.MoveNext ()
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Amazon.Runtime.Internal.UnityMainThreadDispatcher:ProcessRequests()
Amazon.Runtime.Internal.UnityMainThreadDispatcher:Update()

Expected Behavior It used to work seamlessly in Unity version 5.6

Steps to Reproduce Simply running example scene can reproduce issue

Your Environment I am currently using Unity 2017.1.0b2 and building for MAC platform. .NET version in Unity build settings: 3.5

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 31 (2 by maintainers)

Most upvoted comments

I did a little more investigation. It looks like AWSSDK doesn’t properly detect that it should be using UnityWebRequest in Unity 2017.1.0bX.

If I manually set the client it seems to be working fine. Amazon.AWSConfigs.HttpClient = Amazon.AWSConfigs.HttpClientOption.UnityWebRequest;

I’m experiencing a similar issue with Cognito Identity and Unity 2017.1.0b4 on MacOS.

Unity made some additional changes to UnityWebRequest in 2017.1.0b3/b4.

Web: It is now allowed to override User-Agent header in UnityWebRequest Unity Beta Release Notes

I’ve tried with both MobileAnalytics and the S3 sample (in a new empty project). After adding Ids/regions to the sample script and starting the project I get the following error:

InvalidOperationException: Cannot override system-specified headers
UnityEngine.Networking.UnityWebRequest.SetRequestHeader (System.String name, System.String value) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/UnityWebRequest/WebRequestBindings.gen.cs:471)
UnityEngine.WWW..ctor (System.String url, System.Byte[] postData, System.Collections.Generic.Dictionary`2 headers) (at /Users/builduser/buildslave/unity/build/Runtime/WebRequestWWW/UWRWWW.cs:62)
Amazon.Runtime.Internal.UnityMainThreadDispatcher+<InvokeRequest>d__7.MoveNext ()
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Amazon.Runtime.Internal.UnityMainThreadDispatcher:ProcessRequests()
Amazon.Runtime.Internal.UnityMainThreadDispatcher:Update()

Looks like the _credentials = new CognitoAWSCredentials(IdentityPoolId, _CognitoIdentityRegion); is where it breaks.. My wrong, error is in the actual S3 request, so same place as was reported earlier.

UnityPackage:

  • AWSSDK.S3.3.3.6.0.unitypackage

I downloaded the Unity SDK from here http://sdk-for-net.amazonwebservices.com/latest/aws-sdk-unity.zip

Here is function I am using from S3Example.cs

public void GetObjects(Action callback)
   {
       var request = new ListObjectsRequest()
       {
           BucketName = S3BucketName
       };
  
       Client.ListObjectsAsync(request, (responseObject) =>
           {
               if (responseObject.Exception == null)
               {
                   responseObject.Response.S3Objects.ForEach((o) =>
                       {
                           s3Objects.Add(o);
                       });
                   callback();
                   
               }
               else
               {
                   Debug.Log("GetObjects got exceptional :D");
               }
           });
   }

Error is in following line

        Client.ListObjectsAsync(request, (responseObject) =>

You can see exception stack trace in question above Thanks for taking time!