aws-sdk-net: Unity SDK - S3 PostObject Amazon.Runtime.Internal.HttpErrorResponseException when using S3CannedACL.PublicRead

AWS SDK version: aws-sdk-unity_3.1.57.0 Platform: Unity v5.3.4f1 (Mac OS Unity Editor and iOS 8.0 onwards)

When posting a file to a S3 bucket using the S3CannedACL.PublicRead, an Amazon.Runtime.Internal.HttpErrorResponseException is returned. Using the same code but with S3CannedACL.Private, the file is successfully uploaded.

The request is formed as follows:

        var request = new PostObjectRequest()
        {
            Bucket = S3BucketName,
            Key = fileName,
            InputStream = stream,
            CannedACL = S3CannedACL.PublicRead
        };

Is S3CannedACL.PublicRead not a valid option? Or does the bucket need to be configured differently?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 43 (3 by maintainers)

Most upvoted comments

Hi Guys, I would suggest to change your post request to this ->

           var request = new PostObjectRequest()
           {
                Bucket = S3BucketName,
                Key = fileName,
                InputStream = stream,
                CannedACL = S3CannedACL.Private,
                Region = _S3Region
            };

In my case the default region used by the request was not the one that I need 😃

I’m also using S3Example.cs from Unity AWSSDK and got HttpErrorResponseException, then after i setting AWSConfigs in Start()

        void Start()
        {
            UnityInitializer.AttachToGameObject(this.gameObject);
            GetBucketListButton.onClick.AddListener(() => { GetBucketList(); });
            PostBucketButton.onClick.AddListener(() => { PostObject(); });
            GetObjectsListButton.onClick.AddListener(() => { GetObjects(); });
            DeleteObjectButton.onClick.AddListener(() => { DeleteObject(); });
            GetObjectButton.onClick.AddListener(() => { GetObject(); });

            AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;

            AWSConfigs.LoggingConfig.LogTo = LoggingOptions.UnityLogger;
            AWSConfigs.LoggingConfig.LogResponses = ResponseLoggingOption.Always;
            AWSConfigs.LoggingConfig.LogMetrics = true;
            AWSConfigs.CorrectForClockSkew = true;
        }

now i can see the problem

Received error response: [<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message>
<RequestId>99EB18D75BE52010</RequestId>
<HostId>gl3VFqE2t4esxMl5vXsVROEPZlM5hoXlSTdl3QdH5lJJW+5UYvMDCIg4pqAOYMa+vlux0qrqonw=</HostId></Error>]

try with Full Access Policy and it’s works

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "FullAccessS3",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

To fix the issue with the AWSConfig.XML, just add correctForClockSkew=“true” in the aws tag cf. https://github.com/aws/aws-sdk-unity/blob/master/Assets/AWSSDK/src/Core/Resources/awsconfig.xml

However, I also have the Amazon.Runtime.Internal.HttpErrorResponseException when trying to upload a file (whatever CannedACL I use), but cannot get any log to help me understand where it could come from. (The only difference with the sample is using BasicAWSCredentials instead of CognitoAWSCredentials)

Any pointer would be appreciated.

I ran into the same issue using Unity 2017.3.

It seems they have defaulted the chunkedTransfer to true which is causing me the error

I’ve fixed up the SDK AWS.Core you can grab it here… just replace this with the one inside Unity and you should be good to go.

https://drive.google.com/open?id=1TC_aTv3d6DWc6gtPdEND79jOhbEZ0v3A

Any word on this yet? The one-year anniversary is approaching. There are now three other Unity S3 upload bugs posted, and they all are difficult or impossible for us to debug because of the poor error handling here. Can we get some support for S3 uploads in Unity via .Net, or is it time to move to Azure? Sorry for the saltiness, but I’ve lost a LOT of time on this, chasing wild geese everywhere (“try private instead of publicread”, “specify the region 'cuz it doesn’t default correctly”, “set AWSConfig in code before creating client”) … ugh. The lack of error reporting makes this whole process an even worse nightmare.

I managed to upload the file using PutObjectRequest intead of post.

` Debug.Log(“Creating request object”); var request = new PutObjectRequest() { BucketName = S3BucketName, Key = Path.GetFileName(path), InputStream = stream, CannedACL = S3CannedACL.Private };

    Debug.Log("Making HTTP post call");
    lastRequestSucceed = false;
    try {
        
        Client.PutObjectAsync(request, (responseObj) => {
            
            if (responseObj.Exception == null) {
                Debug.Log(string.Format("object {0} posted to bucket {1}", responseObj.Request.Key, responseObj.Request.BucketName));
                lastRequestSucceed = true;
            } else {
                Debug.Log("\nException while posting the result object");
                Debug.Log(string.Format("\n receieved error {0}", responseObj.Response.HttpStatusCode.ToString()));
            }
            isLastRequestDone = true;
        });
    }
    catch (Exception ex) {
        Debug.Log("Unhandled Exception while posting the result object");
        Debug.Log(string.Format("\n received error {0}", ex.ToString()));

    }`

Hi Max,

I did finally get things to work, but unfortunately can’t recall what specific steps I took to get that way. My code is very similar to yours, with the exception that I do not set the Region and ContentType in my request (my region is the same as that in my client, so it didn’t matter despite what others have said, it appears). Also, and perhaps more applicable to your specific issue, I’m using a try/catch block around my PostObjectAsync call so that I can get more information from unhandled exceptions when things fail. You’ll note the slight difference in the error string printed from the two error cases. Hope it helps! My code is below.

try {
	Client.PostObjectAsync(request, (responseObj) =>
	{
		if (responseObj.Exception == null)
		{
			Debug.Log(string.Format("\nobject {0} posted to bucket {1}",
						responseObj.Request.Key, responseObj.Request.Bucket));
			state = UploadState.success;
		}
		else
		{
			Debug.Log("Exception while posting the result object");
			Debug.Log(string.Format("\n received error {0}", responseObj.Exception.ToString()));
			state = UploadState.fail;
		}
	}, new AsyncOptions { ExecuteCallbackOnMainThread = false });
}
catch(Exception ex) {
	Debug.Log("Unhandled Exception while posting the result object");
	Debug.Log(string.Format("\n received error {0}", ex.ToString()));
	state = UploadState.fail;
}