Uploading to S3!
Objective: Upload to S3
In this tutorial we are going to add helper methods to our AWS Manager that is going to allow us to upload and download files. We are going to focus on just uploading, we’ll handle the downloading in a later tutorial. Inside the AWS Manager we are going to create a method taht is going to allow us to upload a file.
The fileName is going to be the persistent Data Path of our case file that we saved. We already created and saved a .dat file, we are now going to send to the AWS Manager, the location of the file and upload it. We need a to create a stream and open that file.
We have created a stream! The next part is going to be to generate a request to upload this to the server. This is going to be a Post Object Request, that is how you actually post objects to the S3 server.
Within this we are going to specify the parameter, fill out the constructer of this new Post Object Request.
Next, is to post the object. Now that we’re generating a request to post it we need to make use of the request.
Now if the response object is null then we have successfully posted to the bucket and if it is not null then we need to print out the exception.
Now we are to the point we need to call this method. Navigate to the UI Manager.
Now run and test it!
If you look in your bucket you will notice that the upload has included the directory.
The reason for that is we are passing in the entire directory path, and it is recreating that. Let’s make it just the casefiles. We are going to change the fileName to the ending of the stream. So, we need to pass in 2 parameters.
Now we need to pass in the fileName in the UI Manager.
Back in the AWS Manager we need to change the string fileName.
Now when you upload it will just upload the casefile! In the next tutorial we are going to finish the uploading process, I’ll see you in the next tutorial!