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

Azure Privilege Escalation via Azure API Permissions Abuse

Sorting Algorithms — With Python

Read this to kickstart your Web Development journey!

How I see Joel's list 18 years later

Web Server Live Updates using Dynamic Distributed Clusters with Kubernetes Deployment

Python — Operators -1:

What are the Challenges & Solutions While Developing Cross-Platform Mobile Apps?

Top 10 Event App Development Companies in 2020

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

Client Authentication with AMQ Stream Operator #1

Singpass Login API Integration-part 1

Edge Computing Nodes in Manufacturing: Benefits in Real-World Applications

Bluetooth Low Energy (BLE) Tutorial for Beaglebone using BleuIO