To be able to send photos, we will have to use a source of photos. In our case, we will be using the phone's camera as the source. The camera will return the photo as a stream after it has been taken. We need to convert that stream into a byte array and then Base64 encode it into a string that is easy to send over SignalR.
The method that we are about to create, called ReadFully(), takes a stream and turns it into a byte array, which is a step toward achieving the Base64-encoded string. This is a standard piece of code that creates a buffer that will be used when we are reading the Stream parameter and writing it to MemoryStream in chunks until we have read the full stream, hence the name of the method.
Perform the following steps and check out the code to get to grips with it:
- Create a method called ReadFully that takes a stream called input as a parameter and returns a byte array.
- Inside a using statement, create a new MemoryStream called ms.
- Copy the...