Let’s Refractor our AWS Manager!
Objective: Refractor the AWS Manager
At this point of our process, we now have our bucket name being printed out in the console view. The next step would be to upload an object. To upload an object, we are going to write our object to a stream, and we already have. Then, create a PostObjectRequest and specify the key, bucket name, and stream data.
The AWS SDK for Unity uses the WWWHTTPClient which does not support the Http put operation. In order to upload an object to your S3 bucket you need to use S3’s browser post.
Let’s open our UI Manager and we want to get access to our file location so copy the code “Application.persistantDataPath + “/case#” + awsCase.CaseID + “.dat”;
Take this information and turn it into a string.
This will make it a lot easier to grab that file using this variable. Now we want to take that filePath and upload it to the server, so we need to tell the AWS where that filPath is.
We are going to do this using our AWS Manager. We need to be able to get access to S3Client because we are going to have a function call in here. In order for this to work we need to be able to access this S3Client because we have to use that PostObject method and the PostObjectAsync methods which comes from the client. The best thing to do here would be to turn the AWS Manager into a singleton.
This way we can easily access the AWS Manager. Don’t forget to assign it in the awake method.
Now that we have access to the AWS we want to make sure we always have access to Amazon’s S3 Client so we are going to turn it into a property.
This will set us up perfectly to begin uploading to S3 in the next tutorial. Also, it is important to note that a majority of issue people deal with when attempting to do this for the first time is issues with their region. So, pay special attention when setting your region, and I’ll see you in the next tutorial!