Daily Progress — Uploading to S3

After refactoring the AWSManager, we’re ready to give it helper methods to upload and download files. Right now, we’ll focus on uploading:

Creating a function that will upload to S3, Amazon will try to recreate your file path which can be cumbersome, so we’ll specify a direct file path for amazon to create. caseID will be the persistentDatapath of the casefile we saved. So here we’ll give amazon the physical location of our case file.

The first thing we’ll do in our method is open a filestream and give the proper options for allowing reading and writing.

The next part is a request to actually upload to the server. This is done with the PostObjectRequest which requires 5 parameters: the bucket name for our project, Key/filename, InputStream, and cannedACL (which sets permissions for access) and region.

That was the request, now we’ll actually post it with the S3Client using the PostObjectAsync parameter. we give it the request and the amazon service callback, a lambda expression/delegate that gets stored into a variable. We’ll pass in a variable called responseObj. (name doesn’t matter) for a response callback, if it’s null, that’s good, it means there’s no problem so we post our info to the bucket. else, we’ll get an error and see what it is with responseObj.Exception.

Back in the UIManager, we’ll update the SubmitButton code with the proper parameters, the physical location of the case file, and the case ID associated with it.

To test things out, I created a couple cases and submitted them.

And hooray! It uploaded to Amazon!!!

--

--

cartoonist, game artist, and wanabe gamedev.

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