Data Communication with AWS: Part 4- App Dev Series 10

Objective: upload file to S3 bucket.

Photo by Chris Ried on Unsplash

Now we have prepared everything needed to upload our file to S3, let’s get to it.

Method to upload

According to the documentation of AWS SDK for Unity, we need to declare a file path to S3 bucket, then set the information of file-to-upload, and we can “Post” this file to check the result.
We will do these part one by one.

Create a public method in AWSManager script, which will be called when user would like to submit the data.
Inside this method, first we need to create a FileStream to locate the file to upload. And use the pass in string as file path, which we will send the path from UIManager.

Then use PostObjectRequest to gather the information of file to send.
Within this, it would need to require some key info:

  • Bucket: the bucket name of your S3.
  • Key: the file name.
  • InputStream: the direction of file.
  • CannedACL: access permission of this file in S3 bucket.
  • Region: the region you set for this bucket.

Using these info as a new PostObjectRequest().

Now we can request to client to upload this object by using PostObjectAsync.
We will need an if statement to check the exception of response object. If there is no exception, then the object has successfully uploaded.

That’s all for this method to upload.
Now we just need to call this method and the object would be uploaded to S3.

File ID from app before uploading.
Uploaded object on S3 bucket.

--

--

--

A passionate gamer whose goal is to work in video game development.

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

Recommended from Medium

OOPS- Not Oops! anymore

How we’ve managed Video on Demand Delivery Workflows with FFMPEG, SOX, FFMBC & our VOD-XML Metadata…

Software for Assets Management

Boost Productivity, Create Company-Wide Efficiency With Citizen Developers

Using Slack apps to drive development productivity at USA TODAY NETWORK

Determining How Long Powerup Effects Should Last- Game Dev Series 17

Using Approov in Your Cordova App the Easy Way

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Puppeteer : Is it time to ditch Selenium?

Implementing Native Camera Plugin for Android!

Git, Gitlab, Gitflow: Time and space travelling’s traffic laws

How to Solve Cleartext HTTP traffic not permitted Error in Android Studio