Creating a Search and Callback System, Part 3 — Downloading the file and Deserializing it back into an object.
Now that we have the ability to find the case, now we download it.
In AWSManager, where we find the file, we’ll use the GetObjectAsync method to stream our object's data into our object.
Taking the code from Amazon’s s3 example, things should start to look familiar. Using the GetObjectAsync command, we pass our bucket name in the form of a variable, our target (the successful case number), and a new lambda placed in responseObject. In this case, we want to read the data and put it back into our Case object. The example provides something for a text file, but our file is a serialized set of information that contains text and images and requires deserialization, so the process will be a little different:
Check to see if the stream is not empty or null. if it isn’t we have a file and can continue.
Create a byte array to store data from the file.
Create a stream reader to read the response data from that file .
Create a memory stream reader to access the stream reader byte by byte.
Finally, we’ll populate a new databyte array with our memorystream data.
I made a lot of comments that explain what’s happening so I’ll just let the code snippet do the talking. :)
Let’s see if we’re able to successfully get the case name from file 329:
It found the case, and we were able to deserialize it and get the client/case name! Next, we’ll finalize a few things on the search panel!