Uploading and downloading from AWS S3 in Unity

Let’s go over how to upload and download data from AWS S3 in Unity

This article go over how to upload and downloaded the data from this article. I showed how to get started with S3 in this article.

First, open up the AWSManager script and add the function called UploadToS3. Create a new FileStream and pass in the file path, set FileMode to open, FileAcess to read and write and FileShare also to read and write:

Create the S3 PostObjectRequest using the name of the bucket, set the file name, add the file stream, set access level and also set the region:

The last part is to submit the request. If successful call LoadScene to get back to the beginning:

Open the UIManager script and call the UploadToS3 function from the submit function:

To download from S3 go back to the AWSManager script and add the using directives System.Linq and System.Runtime.Serialization.Formatters.Binary:

Add the function LoadFromS3. Add a local string called target and a ListObjectsReqest:

Downloading the data takes few more steps than to upload. Similar to the upload you start with submitting the request. Using linq we check if a matching object is found:

If object is found we will request that object from the S3 storage:

The tricky part with downloading from S3 storage is that it is held in memory and not stored on your device. For us to make use of the data we first need to temporarily store this information in a byte array:

Once we have the data we can deserialize it and add it back to our data class:

Lastly, call the LoadFromS3 function:

Good luck!




Unity / C# Game developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Too Many Choices: how to pick the right tool to manage your Docker clusters

Captain! Our Shields are Failing!

Distinction Between Operational And Programmer Error in Nodejs

Hosting WordPress considering Database security on AWS Cloud

Set Up a “Hello World” Project Using Django REST Framework

READ/DOWNLOAD@! Exam Ref 70–741 Networking with Wi


How to add firebase_admob in a Flutter App

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Niklas Bergstrand

Niklas Bergstrand

Unity / C# Game developer

More from Medium

How to Configure Local Preference in BGP

Copying AWS S3 Objects from One Account to Another.

CS50 pset3 Tideman (Merge sort)

Try to use Synthesizer V