🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

I Can´t upload an aws bucket in Unity

Started by
0 comments, last by LuisFer Ruelas 5 years ago

I´m trying to upload an aws bucket but I got this error :

Exception ocurred during uploading: Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
  at Amazon.Runtime.Internal.UnityRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x0000e] in <bcd90127d6ba43f0a6549cfab9c38753>:0
  at Amazon.S3.AmazonS3Client.ProcessPostResponse (System.IAsyncResult result) [0x0001c] in <ea4aaa89494447eea8cc56857faf4272>:0
UnityEngine.Debug:Log(Object)
<>c:<UploadToS3>b__10_0(AmazonServiceResult`2) (at Assets/Scripts/AWSManager.cs:86)
Amazon.S3.<>c__DisplayClass7_0:<PostObjectAsync>b__0(AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions)
Amazon.Runtime.Internal.UnityMainThreadDispatcher:ProcessRequests()
Amazon.Runtime.Internal.UnityMainThreadDispatcher:Update()

Here´s my code, can anybody help ?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.Runtime;
using System.IO;
using System;
using Amazon.S3.Util;
using System.Collections.Generic;
using Amazon.CognitoIdentity;
using Amazon;
using Facebook.Unity;

public class AWSManager : MonoBehaviour
{
private static AWSManager _instance;
public static AWSManager Instance {
get {
if (_instance == null){
Debug.LogError("AWS Manager is null");
}
return _instance;
}
}

public string S3Region = RegionEndpoint.USEast2.SystemName;
private RegionEndpoint _S3Region {
get { return RegionEndpoint.GetBySystemName(S3Region); }
}

private AmazonS3Client _s3Client;
public AmazonS3Client S3Client {
get {
if (_s3Client == null){
_s3Client = new AmazonS3Client(new CognitoAWSCredentials (
"us-east-2:0267fa51-2e5f-44d5-80e3-f812fdc5ed20", //Identity Pool ID
RegionEndpoint.USEast2 //Region
), _S3Region);
}
return _s3Client;
}
}

private void Awake(){

_instance = this;

UnityInitializer.AttachToGameObject(this.gameObject);
AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;

// ResultText is a label used for displaying status information
S3Client.ListBucketsAsync(new ListBucketsRequest(), (responseObject) =>
{
if (responseObject.Exception == null)
{
responseObject.Response.Buckets.ForEach((s3b) =>
{
print ("Bucket Name: " + s3b.BucketName);
});
}
else
{
print ("AWS Error: " + responseObject.Exception);
}
});

}

public void UploadToS3(string fileName){
FileStream stream = new FileStream(fileName,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

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

S3Client.PostObjectAsync(request, (responseObj) => {
if (responseObj.Exception == null) {
Debug.Log ("Successfully posted to bucket");
} else {
Debug.Log ("Exception ocurred during uploading: " + responseObj.Exception);
}
});
}
}

I´m trying to upload an aws bucket but I got this error :
Exception ocurred during uploading: Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
  at Amazon.Runtime.Internal.UnityRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x0000e] in <bcd90127d6ba43f0a6549cfab9c38753>:0
  at Amazon.S3.AmazonS3Client.ProcessPostResponse (System.IAsyncResult result) [0x0001c] in <ea4aaa89494447eea8cc56857faf4272>:0
UnityEngine.Debug:Log(Object)
<>c:<UploadToS3>b__10_0(AmazonServiceResult`2) (at Assets/Scripts/AWSManager.cs:86)
Amazon.S3.<>c__DisplayClass7_0:<PostObjectAsync>b__0(AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions)
Amazon.Runtime.Internal.UnityMainThreadDispatcher:ProcessRequests()
Amazon.Runtime.Internal.UnityMainThreadDispatcher:Update()
 
Here´s my code, can anybody help ?
 
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.Runtime;
using System.IO;
using System;
using Amazon.S3.Util;
using System.Collections.Generic;
using Amazon.CognitoIdentity;
using Amazon;
using Facebook.Unity;
 
public class AWSManager : MonoBehaviour
{
private static AWSManager _instance;
public static AWSManager Instance {
get {
if (_instance == null){
Debug.LogError("AWS Manager is null");
}
return _instance;
}
}
 
public string S3Region = RegionEndpoint.USEast2.SystemName;
private RegionEndpoint _S3Region {
get { return RegionEndpoint.GetBySystemName(S3Region); }
}
 
private AmazonS3Client _s3Client;
public AmazonS3Client S3Client {
get {
if (_s3Client == null){
_s3Client = new AmazonS3Client(new CognitoAWSCredentials (
"us-east-2:0267fa51-2e5f-44d5-80e3-f812fdc5ed20", //Identity Pool ID
RegionEndpoint.USEast2 //Region
), _S3Region);
}
return _s3Client;
}
}
 
private void Awake(){
 
_instance = this;
 
UnityInitializer.AttachToGameObject(this.gameObject);
AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
 
// ResultText is a label used for displaying status information
S3Client.ListBucketsAsync(new ListBucketsRequest(), (responseObject) =>
{
if (responseObject.Exception == null)
{
responseObject.Response.Buckets.ForEach((s3b) =>
{
print ("Bucket Name: " + s3b.BucketName);
});
}
else
{
print ("AWS Error: " + responseObject.Exception);
}
});
 
}
 
public void UploadToS3(string fileName){
FileStream stream = new FileStream(fileName,
FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
 
PostObjectRequest request = new PostObjectRequest(){
Bucket = "reservacionfiles",
Key = fileName,
InputStream = stream,
CannedACL = S3CannedACL.Private,
Region = _S3Region
};
 
S3Client.PostObjectAsync(request, (responseObj) => {
if (responseObj.Exception == null) {
Debug.Log ("Successfully posted to bucket");
} else {
Debug.Log ("Exception ocurred during uploading: " + responseObj.Exception);
}
});
}
}

This topic is closed to new replies.

Advertisement