Download file and Convert to Object!
Objective: Now that you found the case, we need to download it!
In the case found bool we created in the last tutorial, that’s where we will download it. We can reference the documentation we’ve been using as a guide for this process.
When we uploaded our file, we serialized out date. This mean it is going to be a big undertaking to retrieve this date.
Memory stream is going to allow us to access deeper into the reader stream and grab the individual bytes.
We are going to populate the byte array through the memory stream. We need to use a stream reader to read this response stream. Inside the response stream is our file and we need to load it.
Now that we have access to that info, we can now read it. We need to go a little deeper, we need access to the memory stream. There is no way to get the bytes without the memory stream.
The bytesRead is going to purse individual bytes and populate our data. Next, we need a while loop to read these bytes and purse through the bytesRead.
While there is information to be read and it is greater than 0. Once we’ve hit the end of the file, we are just reading the file and then we are going to create the data.
This will populate data with everything we have. We now have all our info in the bytes. Now, we need to convert bytes to a case object. To do that we need another memory stream.
We need to use a binary formatter to reconstruct it. Remember the name space.
Using the debug log you can now save and test your code and if done right you console will print out the name associated to that case. I’ll see you in the next tutorial!